Unable to run nohup command from jenkins as a background process Unable to run nohup command from jenkins as a background process unix unix

Unable to run nohup command from jenkins as a background process


In your jenkins shell script try:

  export BUILD_ID=dontKillMe  nohup java -jar your_java_app.jar &

It worked for me!


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.


I tried every possible combination with BUILD_ID but it didn't work.I made it though by putting "nohup command > output.txt&" inside a shell script ran by the execute shell in jenkins, it worked perfectly!