jenkins deployment of continuous integration tools (Part 2)

1, Foreword

The first part mainly introduces the basic environment configuration during jenkins deployment. This part introduces how to use jenkins to publish the project to the remote server

2, Project deployment release

1. New task

Enter the task name, select build maven project, and click OK

2. Parametric build process (optional)

Note: the parametric construction process can provide the key value pair parameters required for maven construction, such as the following figure

3. Source code management

Version control is selected according to the project. This paper takes svn as the case, so Subversion is selected

Fill in SVN remote server address: http://localhost/svn/Muse-Workflow@HEAD, @ head means to take the latest version on the SVN server and select the configured SVN Certificate (i.e. the user name and password to access the SVN server)

4. Build environment

Select Send files or execute commands over SSH after the build runs

5. Build environment (parameter introduction)

a. Sourec files refers to the jar, war or other compressed package to be executed for configuration. b. Remove prefix refers to removing the prefix directory. The compressed package of this project is under the target under the root directory, so the target directory c. Remote directory refers to the directory where the compressed package is to be transmitted to the target server. d. Exec command is the directory of remote scripts to be executed and deployed to achieve the purpose of automatic deployment. If you don't write scripts, jenkins can only help you send compressed packages to the target server. e. Check "Add timestamps to the Console Output" in the build environment, and the log will be printed during code building

6,Build

Enter the maven packaging command

clean package  -P dev -Dlogstash.host=${logstashHost} -Dfile_server_addr=${fileServerAddr} -Dfastdfs.tracker_servers=${fastdfsTrackerServers} -Dmaven.test.skip=true Click save

3, Run build

Select Build with Parameters

View console output

It can be seen from the log that the build and release were successful

4, Summary

The above is an example of publishing a project to a remote server through jenkins. If the company develops its own public jar package, remember to update it to the maven private server in time to avoid project publishing failure. As for how to establish maven warehouse private server through nexus, share a tutorial another day

5, Appendix some script parameters

1. In this example, unzip the zip and execute the publish command script

cd /root/oaCore/${project_name}/${BUILD_TIMESTAMP}
ls -a | sort -r | head -n 1 | xargs unzip
cd $(ls -a | sort -r | head -n 1 | xargs -I {} basename {} .zip)
sh install.sh
sleep 3
service ${project_name} start

2. Common execution script for springboot project

#!/bin/bash

SpringBoot=$2

if [ "$1" = "" ];
then
    echo -e "\033[0;31m Operation name not entered \033[0m  \033[0;34m {start|stop|restart|status} \033[0m"
    exit 1
fi

if [ "$SpringBoot" = "" ];
then
    echo -e "\033[0;31m App name not entered \033[0m"
    exit 1
fi

function start()
{
    count=`ps -ef |grep java|grep $SpringBoot|grep -v grep|wc -l`
    if [ $count != 0 ];then
        echo "$SpringBoot is running..."
    else
        echo "Start $SpringBoot success..."
        nohup java -jar $SpringBoot > /dev/null 2>&1 &
    fi
}

function stop()
{
    echo "Stop $SpringBoot"
    boot_id=`ps -ef |grep java|grep $SpringBoot|grep -v grep|awk '{print $2}'`
    count=`ps -ef |grep java|grep $SpringBoot|grep -v grep|wc -l`

    if [ $count != 0 ];then
        kill $boot_id
        count=`ps -ef |grep java|grep $SpringBoot|grep -v grep|wc -l`

        boot_id=`ps -ef |grep java|grep $SpringBoot|grep -v grep|awk '{print $2}'`
        kill -9 $boot_id
    fi
}

function restart()
{
    stop
    sleep 2
    start
}

function status()
{
    count=`ps -ef |grep java|grep $SpringBoot|grep -v grep|wc -l`
    if [ $count != 0 ];then
        echo "$SpringBoot is running..."
    else
        echo "$SpringBoot is not running..."
    fi
}

case $1 in
    start)
    start;;
    stop)
    stop;;
    restart)
    restart;;
    status)
    status;;
    *)

    echo -e "\033[0;31m Usage: \033[0m  \033[0;34m sh  $0  {start|stop|restart|status}  {SpringBootJarName} \033[0m
\033[0;31m Example: \033[0m
      \033[0;33m sh  $0  start esmart-test.jar \033[0m"
esac

Added by kulikedat on Thu, 10 Mar 2022 07:47:13 +0200