16

I'm running a shell command at the end of a Jenkins deployment to restart a forever script:

npm install && forever stop app.js && forever start -a -l /var/log/forever.log app.js

When I run that as a user jenkins everything works fine and the console output from the build history also tells me that the forever script is running. However, the process stops right after the deployment is finished and the forever process is stopped.

What causes this behavior and how can I fix it?

29

Jenkins kills all process spawn by the job.

This can be disabled by setting the BUILD_ID environment variable to something else:

export BUILD_ID=dontKillMe

see https://wiki.jenkins-ci.org/display/JENKINS/ProcessTreeKiller for details

  • 1
    Is this a 'clean' way to do or something else recommended? – Patrick Apr 26 '13 at 10:17
  • As far as I know, it's the only way to disable the ProcessTreeKiller – rcomblen Apr 26 '13 at 13:00
  • rcomblen is correct, check out wiki.jenkins-ci.org/display/JENKINS/ProcessTreeKiller – Jan Molak Jan 2 '14 at 18:13
  • Before this I was getting. [ssh-agent] Stopped. Killed by signal 15. Killed by signal 15. After this I got [ssh-agent] Stopped. But it is still being killed :( – Amit Kumar Gupta Mar 15 '16 at 17:09
1

The question is quite old, but there is a better solution in this case I think.

Use Post-Build Script Plug-In

The plugin itself is not updated since the beginning of 2016, but it does the job and you do not have to fiddle with environment variables. Seems a bit neater to me.

0

In the new Pipeline jobs, setting BUILD_ID no longer works. Instead, you need to set JENKINS_NODE_COOKIE to prevent Jenkins from killing your process when the job finishes.

sh 'export JENKINS_NODE_COOKIE=dontKillMe'
sh 'myProcess'

Or, more selectively:

sh 'JENKINS_NODE_COOKIE=dontKillMe myProcess'

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.