文章目录
- jenkins部署Springboot项目步骤
- 创建一个jenkins任务
- 开始配置
- 准备步骤添加shell脚本(两个)你放一个执行也行
- 构建成功后执行脚本
如何在linux上安装jenkins可以看上一篇
linux安装jenkins(详细步骤)
jenkins部署Springboot项目步骤
创建一个jenkins任务
开始配置
![在这里插入图片描述](https://img-blog.csdnimg.cn/d5ffa0ec0ebd41c9a5ef28cbcf994807.png
准备步骤添加shell脚本(两个)你放一个执行也行
#!/bin/bash
# 服务器脚本存放位置
cd /opt/java/tingyuan
# 执行脚本
./jenkins-star-honey-popularize-server.sh stop
#!/bin/bash
mvn clean install -Dmaven.test.skip=true
构建成功后执行脚本
#!/bin/bash
cd /opt/java/tingyuan
export EXEC=./jenkins-star-honey-popularize-server.sh restart
$EXEC stop
sleep 5
BUILD_ID=dontKillMe $EXEC start
然后点击保存即可
#!/bin/sh
export service=/var/lib/jenkins/workspace/tingyuan/star-honey-popularize-server/target/star-honey-popularize-server-0.0.1-SNAPSHOT.jar
export service_port=7099
export service_enable=true
case "$1" in
start)
if($service_enable);then
echo "--------service 开始启动--------------"
nohup java -jar $service >/dev/null 2>&1 &
service_pid=`lsof -i:$service_port|grep "LISTEN"|awk '{print $2}'`
until [ -n "$service_pid" ]
do
service_pid=`lsof -i:$service_port|grep "LISTEN"|awk '{print $2}'`
sleep 3
done
echo "service pid is $service_pid"
echo "--------service 启动成功--------------"
fi
echo "===startAll success==="
;;
stop)
## 杀掉gateway
P_ID=`ps -ef | grep -w ${service##*/} | grep -v "grep" | awk '{print $2}'`
if [ "$P_ID" == "" ]; then
echo "===service process not exists or stop success"
else
kill -9 $P_ID
echo "service killed success"
fi
echo "===stopAll success==="
;;
restart)
$0 stop
sleep 2
$0 start
echo "===restartAll success==="
;;
esac
exit 0