直接上图
1、新建任务

2、配置





#!/bin/bash
#服务名称
SERVER_NAME=pm-admin-bs-1.0
# 源jar路径,mvn打包完成之后,target目录下的jar包名称,也可选择成为war包,war包可移动到Tomcat的webapps目录下运行,这里使用jar包,用java -jar 命令执行
JAR_NAME=pm-admin-bs-1.0
#jenkins 工作目录下target 打包生成jar包的目录
JAR_PATH=/var/lib/jenkins/workspace/bs/pm-admin/target
# 打包完成之后,把jar包移动到运行jar包的目录--->work_daemon,work_daemon这个目录需要自己提前创建
JAR_WORK_PATH=/opt/project/pm
echo "查询进程id-->$SERVER_NAME"
PID=`ps -ef | grep "$SERVER_NAME" | awk '{print $2}'`
echo "得到进程ID:$PID"
echo "结束进程"
for id in $PID
do
kill -9 $id
echo "killed $id"
done
echo "结束进程完成"
#复制jar包到执行目录
echo "复制jar包到执行目录:cp $JAR_PATH/$JAR_NAME.jar $JAR_WORK_PATH"
cp $JAR_PATH/$JAR_NAME.jar $JAR_WORK_PATH
echo "复制jar包完成"
#修改文件权限
chmod 755 $JAR_WORK_PATH/$JAR_NAME.jar
BUILD_ID=dontKillMe nohup java -jar $JAR_WORK_PATH/$JAR_NAME.jar --spring.profiles.active=test &
echo "启动完成"
3、保存并构建

网友评论