jenkins部署jar项目、springboot项目部署
*****1、配置环境
首先是配置jdk、maven、git 如图:
*****2、创建任务(项目)
*****3、源码管理,git地址,和验证配置,点击add里,添加用户名和密码
*****4、重点是脚本
#!/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 &
三个文件内容
==================stop.sh===start=======================
#!将应用停止
#!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 $2}'`
if [ -n "$pid" ]
then
#!kill -9 强制终止
echo "kill -9 的pid:" $pid
kill -9 $pid
fi
==================stop.sh===end =======================
==================replace.sh===start=======================
jar_name=cmp-0.0.1-SNAPSHOT.jar
#!编译好的jar包存放地址
file_path=~/.jenkins/workspace/cmp/target
#!将现有的jar备份后,将新的jar包替换
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 "授予当前用户权限"
chmod 777 /deploy_cmp/cmp-0.0.1-SNAPSHOT.jar
echo "执行....."
cd /deploy_cmp
java -jar cmp-0.0.1-SNAPSHOT.jar
echo "**********************cmp on jenkins started*************************"
==================startup.sh===end =======================
应用保存后,直接 构建项目。
参考地址: https://blog.csdn.net/shenhonglei1234/article/details/71480064