使用jenkins ssh插件传送编译后的jar包至远程后,执行远程的启动脚本,脚本是执行了,但是其中的nohup java -jar xxx.jar & 始终无法启动,试了在jenkins 中指定BUILD_ID=DotKillMe ,试了在nohup前添加BUILD_ID=DotKillMe ,还有在脚本里添加export BUILD_ID=DotKillMe 都不起作用。最终是在nohup前执行source /etc/profile 解决这个问题,也不需要export BUILD_ID=DotKillMe ,使用这个变量编译总是超时警告,显示编译并不是成功,如果有强迫症的话一定看着很不爽。下面搞一个完整的例子:
#!/bin/bash
pid=`ps -ef | grep "xxx-service-1.0.jar" | grep -v grep | awk '{print $2}'`
if [ "$pid" != "" ];then
echo "already start pid: $pid"
echo "kill first then start"
kill -9 $pid
fi
source /etc/profile
`nohup java -jar /jarpath/xxx-service-1.0.jar ---spring.profiles.active=dev -Dlog.level=debug >/dev/null 2>&1 &`
关键点就在source /etc/profile
完美启动