Unable to run nohup command from jenkins as a background process

后端 未结 7 2001
醉话见心
醉话见心 2021-02-15 10:59

UPDATE: Based on below discussion I have edited my answer for more accurate description.

I am trying to run a nohup command from jenkins. The full command is

         


        
7条回答
  •  说谎
    说谎 (楼主)
    2021-02-15 11:11

    Long story short, Jenkins kills all processes spawned by a job once that job finishes. To override this behavior, you need to set an environment variable.

    The variable appears to vary from job type to job type. It used to be BUILD_ID, but for Pipeline jobs it is JENKINS_NODE_COOKIE, and there are several others mentioned in this answer.

    So if you're running your command in Pipeline, it would look like this:

    sh 'JENKINS_NODE_COOKIE=dontKillMe nohup java -jar /home/.../jar/server-process-0.35.jar prod >> /var/../server-process-prod.log 2>&1 &'
    

    See the wiki on ProcessTreeKiller and this comment in the Jenkins Jira for more information.

提交回复
热议问题