从詹金斯(Jenkins)在后台启动shell脚本的干净方法 [英] Clean way of launching a shell script in background from Jenkins
问题描述
从jenkins启动脚本,不使构建挂起并使进程运行的正确方法是什么?我似乎无法正常工作.脚本无法运行或构建挂起.
What's the proper way to launch a script from jenkins, don't get the build hanging, and leave the process running? I can't seem to get it to work. Either the script doesn't run or the build hangs.
如果我将构建的执行外壳"步骤放入bash relaunch.sh &
或relaunch.sh > output.log &
或nohup bash relaunch.sh &
,
什么都没发生;构建完成,但该过程未运行.我想这可能与詹金斯(Jenkins)等待错误管道关闭有关.
If I put in the build's "Execute shell" step bash relaunch.sh &
or relaunch.sh > output.log &
or nohup bash relaunch.sh &
,
nothing happens; build finishes, but the process doesn't run. I guess it can be related to Jenkins waiting for the error pipe to close.
如果我愿意
nohup bash relaunch.sh 2>&1 > output.log
根据建议此处,输出已正确重定向,但构建挂起(未完成),并且在我终止构建时进程死了.
If I do
nohup bash relaunch.sh 2>&1 > output.log
as suggested here, the output is properly redirected, but the build hangs (doesn't finish), and the process dies when I kill the build.
根据建议添加export BUILD_ID=dontKillMe
,此处,此处和
Adding export BUILD_ID=dontKillMe
, as suggested here, here, and here, either to the "Execute shell" step or the script itself doesn't help either. The build hangs and the process dies when I kill the build. Needless to say, my knowledge of linux is very limited.
人们如何以一种干净的方式做到这一点?
How do people do this in a clean way?
推荐答案
一种简便的实现方法是更改 Execute shell 下的环境变量BUILD_ID
,其中Jenkins's
ProcessTreeKiller .
A convenient way to achieve that is to change the environment variable BUILD_ID
under Execute shell which Jenkins's
ProcessTreeKiller is looking for.
这样做,
BUILD_ID=dontKillMe nohup bash relaunch.sh &
Jenkins将假定后台作业不是由构建生成的,并且不会在完成作业后杀死它们.
Jenkins will assume that the background job is not spawned by the build and will not kill them after finishing the job.
感谢 Joshua 的观察,他也可以将JENKINS_NODE_COOKIE
用作
Thanks to Joshua for his observation that you could also use JENKINS_NODE_COOKIE
as
JENKINS_NODE_COOKIE=dontKillMe
这篇关于从詹金斯(Jenkins)在后台启动shell脚本的干净方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!