JEKINS项目的构建流程
1.点击新建任务,新建一个maven项目
2.点击源码管理,git下构建相关git的地址,跟账号密码选择分支等,
3.选择调用顶层Maven目标
maven版本为maven(随便取) 目标 ,和Execute shell script on remote host using ssh
Command里面放的是sh命令
#!/bin/bash
#author: fangzg
#date:2022年10月19日
PID=$(ps -ef | grep service-provider-V1.0-SNAPSHOT-j1.jar | grep -v grep | awk '{ print $2 }')
if [ -z "$PID" ]
then
echo "程序未启动。"
else
echo "程序在启动中,正在停止..."
kill -15 $PID
kill -9 $PID
fi
echo '开启启动程序 ...'
export BUILD_ID=dontKillMe
mv /limaodong/server/service-provider-V1.0-SNAPSHOT-j1.jar /limaodong/server/backup/service-provider-V1.0-SNAPSHOT-j1.jar
cp /home/limaodong/.jenkins/workspace/jekins_test/service-provider/target/service_provider-1.0-SNAPSHOT.jar /limaodong/server/service-provider-V1.0-SNAPSHOT-j1.jar
#nohup java -jar /limaodong/server/service-provider-V1.0-SNAPSHOT-j1.jar > run-server.log 2>&1 &
echo "starting service..."
sleep 20
#根据重启后是否有当前应用判断启动是否成功
endPID=$(ps -ef | grep service-provider-V1.0-SNAPSHOT-j1.jar | grep -v grep | awk '{ print $2 }')
if [ -z "$endPID" ]
then
echo "程序启动失败。"
else
echo "程序重启成功...pid:"${endPID}
fi
点击系统管理,系统设置 设置好ssh remotehost