美文网首页
Jenkins Shell nohup问题

Jenkins Shell nohup问题

作者: 国服最坑开发 | 来源:发表于2023-11-15 18:51 被阅读0次

0x01 现象

jenkins的shell 脚本中,nohup命令死活无法启动任务。
查了一圈大意是说:nohup启动了一个子进程,在jenkins任务执行结束会被一并杀掉。

0x02 解决方法

在脚本中定义一个 BUILD_ID,值可以是任意信息

0x03 Sample

BUILD_ID=magicId

cd /home/jenkins/workplace
/bin/git pull

# stop task
PID=`ps -ef | grep my.py | sed "/grep/d" | head -n 1  | awk '{print $2}'`
if [ -n "$PID" ]; then
  kill -9 $PID
else
  echo "not running"
fi
# start task
/bin/nohup /bin/python3 my.py >> my.log 2>&1 &
echo "DONE"

亲测可用~

相关文章

网友评论

      本文标题:Jenkins Shell nohup问题

      本文链接:https://www.haomeiwen.com/subject/miaswdtx.html