Explain record Jenkins How to deploy a Jar type project (springboot)
1, configure the environment
The first is to configure JDK, maven, Git, as shown:
2, create the Task (project)
3, source management, Git address, and authentication configuration, click Add, add user name and password
4, the key is the script
#!/bin/bash
Cd/deploy_cmp_script
echo "Execute Shell Start"
SH stop.sh
SH replace.sh
echo "Execute Shell Finish"
chmod 777/deploy_cmp_script/startup.sh
Build_id=dontkillme nohup/deploy_cmp_script/startup.sh &
Three contents of a file
==================stop.sh===start=======================
#! will apply to stop
#!stop.sh
#!/bin/bash
Cd/deploy_cmp_script
echo "Stopping Springboot application for CMP"
Ls
Pid= ' Ps-ef | grep Cmp-0.0.1-snapshot.jar | Grep-v grep | awk ' {print $} '
If [-N "$pid"]
Then
#!kill-9 forced termination
echo "kill-9 pid:" $pid
Kill-9 $pid
Fi
==================stop.sh===end =======================
==================replace.sh===start=======================
Jar_name=cmp-0.0.1-snapshot.jar
#! a compiled jar package store address
File_path=~/.jenkins/workspace/cmp/target
#! Replace the existing jar with the new jar package after it is backed up
File= "/deploy_cmp/cmp-0.0.1-snapshot.jar"
If [-F "$file]"
Then
Mv/deploy_cmp/cmp-0.0.1-snapshot.jar/deploy_cmp_backup/cmp-0.0.1-snapshot.jar. ' Date +%Y%m%d%H%M%S '
Fi
CP ~/.jenkins/workspace/cmp/target/cmp-0.0.1-snapshot.jar/deploy_cmp
==================replace.sh===end =======================
==================startup.sh===start=======================
Ehco "Grant Current user rights"
chmod 777/deploy_cmp/cmp-0.0.1-snapshot.jar
echo "Execute ..."
cd/deploy_cmp
Java-jar Cmp-0.0.1-snapshot.jar
echo "**********************cmp on Jenkins started*************************"
==================startup.sh===end =======================
After the application is saved, build the project directly.