最近想使用Jenkins构建项目做持续集成,所有的配置都弄好了,构建显示正常。但是进程就是没起来。
经过一遍一遍检查就这句
sh /root/.jenkins/workspace/aaa.sh start
执行了,也输出了。不知道为什么无效。
贴出aaa.sh内容
APP_NAME=/root/.jenkins/workspace/firstJenkinsProgram/springbootTest/target/springbootbtest-0.0.1-SNAPSHOT.jar
usage(){
echo "Usage: sh **.sh [start|stop|restart|status]"
exit 1
}
is_exist(){
pid=`ps -ef|grep $APP_NAME|grep -v grep|awk '{print $2}' `
if [ -z "${pid}" ]; then
return 1
else
return 0
fi
}
start(){
is_exist
if [ $? -eq "0" ]; then
echo "${APP_NAME} is already running. pid=${pid} ."
else
nohup /opt/jdk1.8.0_221/bin/java -jar $APP_NAME > /data/jenkins/app/admin.log 2>&1 &
echo "${APP_NAME} is running"
fi
}
stop(){
is_exist
if [ $? -eq "0" ]; then
kill -9 $pid
else
echo "${APP_NAME} is not running"
fi
}
status(){
is_exist
if [ $? -eq "0" ]; then
echo "${APP_NAME} is running. Pid is ${pid}"
else
echo "${APP_NAME} is NOT running."
fi
}
restart(){
stop
start
}
case "$1" in
"start")
start
;;
"stop")
stop
;;
"status")
status
;;
"restart")
restart
;;
*)
usage
;;
esac
但是自己在Xshell 执行 sh aaa.sh start 就能把进程启动。
由此确定,脚本是有用的,但是Jenkins的不知道什么骚操作把我的进程又杀死了。
幸得看见大神的博客,顺利解决问题
https://blog.csdn.net/u011781521/article/details/80210985
使用了方法二,
在start()方法里加上BUILD_ID,并设置睡眠时间
如
start(){
is_exist
if [ $? -eq "0" ]; then
echo "${APP_NAME} is already running. pid=${pid} ."
else
export BUILD_ID=dontKillMe
nohup /opt/jdk1.8.0_221/bin/java -jar $APP_NAME > /data/jenkins/app/admin.log 2>&1 &
echo "${APP_NAME} is running"
sleep 10s
fi
}
已经通过验证,完美解决了这个问题!