Jenkins + GitLab + SpringBoot 实现持续集成脚本
Linux脚本
#!/bin/bash jar_name=hq-api.jar cd /usr/local/app/hq-api echo "Stopping SpringBoot Application for Hq-API" ls pid=`ps -ef | grep $jar_name | grep -v grep | awk '{print $2}'` if [ -n "$pid" ] then #!kill -9 强制终止 echo "kill -9 的pid:" $pid kill -9 $pid fi echo "kill完毕" #!编译好的jar包存放地址 file_path=~/.jenkins/workspace/hq-api/target #!将现有的jar备份后,将新的jar包替换 echo "开始替换" if [ -f "$jar_name" ] then mv ./$jar_name ./backup/$jar_name.`date +%Y%m%d%H%M%S` fi cp $file_path/$jar_name . echo "替换和备份完毕" chmod 777 $jar_name echo "启动项目........" java -jar $jar_name >console.log 2>&1 & echo "**********************cmp on jenkins started*************************"
Jenkins脚本:
#!/bin/bash cd /usr/local/app/hq-api BUILD_ID=dontKillMe sh redeploy.sh