Jenkins deploys spring boot project

The deployment of spring boot by jenkins is a bit different from the previous deployment to tomcat and weblogic. Before, there was already a server running that could be completed by remote deployment of the server. Spring boot is an embedded server, so the jar package needs to be sent to Application server, and then start the server through a linux script.

Structure legend:

detailed steps:

Step 1: First configure the jenkins ssh plugin Publish Over SSH

 System management --- plug-in management, install ssh plug-in

The configuration is as follows:

The path of remoto directory means that on the target server, you select a path as the root path of remote operation, and the path of subsequent file transfers is located relative to this root path. I encountered this pit here before, and later used / to express. The following path is filled in according to the actual situation.

Step 2: Create a maven project

The basic code configuration is similar to the tomcat deployment method in the previous article, so I won’t repeat it here. If you have any questions, you can read the previous article  jenkins+svn+ant+weblogic/tomcat continuous integration deployment

The packaging method here is to use maven to compile and package, the configuration is as follows

clean install -Dmaven.test.skip=true -Ptest

Configure compiled ssh service

Attach the script used

DATE=$(date +%Y%m%d)
export JAVA_HOME=/usr/jdk1.8
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$CLASSPATH
DIR=/usr/local/app/leaf6-epbd
JARFILE=leaf6-epbd-rest-1.0.jar

if [ ! -d $DIR/backup ];then
   mkdir -p $DIR/backup
fi
cd $DIR

ps -ef | grep $JARFILE | grep -v grep | awk '{print $2}' | xargs kill -9
mv  $JARFILE backup/$JARFILE$DATE
mv -f /usr/local/jenkins-app/$JARFILE .

java -jar $JARFILE > out.log &
if [ $? = 0 ];then
        sleep 30
        tail -n 50 out.log
fi

cd backup/
ls -lt|wak 'NR>5{print $NF}'|xargs rm -rf

The general meaning of the script is explained:

DIR is the server deployment folder

/usr/local/jenkins-app is the folder that received the jar package

Kill the server thread first, stop the server

Then back up the original package to the backup folder

Finally, put the jar package exported to the server into the deployment folder and start the service

Delete historical backups, the latest few

Guess you like

Origin blog.csdn.net/caicai250/article/details/82862245