Dev
Dev

Reputation: 13773

How to tell jenkins not to kill processes after successful execution of job in multijob project?

I have a jenkins multijob project.

In 1st phase, I start databases and build core part.

sample shell command to start Mongodb:

/root/software/mongodb-linux-x86_64-2.6.3/bin/mongod&

In 2nd phase, I have various jobs to build some clients.

After 1st phase job, after starting servers and building core part. I see logs-

Process leaked file descriptors. See http://wiki.jenkins-ci.org/display/JENKINS/Spawning+processes+from+build for more information
2016-08-26T20:23:00.815+0530 [signalProcessingThread] got signal 15 (Terminated), will terminate after current cmd ends
2016-08-26T20:23:00.833+0530 [signalProcessingThread] now exiting
2016-08-26T20:23:00.879+0530 [signalProcessingThread] dbexit: 
2016-08-26T20:23:00.903+0530 [signalProcessingThread] shutdown: going to close listening sockets...
2016-08-26T20:23:00.903+0530 [signalProcessingThread] closing listening socket: 7
2016-08-26T20:23:00.903+0530 [signalProcessingThread] closing listening socket: 8
2016-08-26T20:23:00.903+0530 [signalProcessingThread] removing socket file: /tmp/mongodb-27017.sock
Finished: SUCCESS

This is stopping all the databases and build is failing for phase2 jobs.

How to tell jenkins not to kill processes after a job?

Upvotes: 9

Views: 23277

Answers (4)

Azeem
Azeem

Reputation: 61

First, update your manual start or stop command inside a shell script and use the following line in your Jenkins pipeline script.

sh script: "export JENKINS_NODE_COOKIE=dontKillMe && sh script.sh"

Upvotes: 2

Jayan
Jayan

Reputation: 18468

Jenkins uses a special mechanism to cleanup child processes. It looks for process with BUILD_ID matching the build number. You can set that to different value and jenkins will skip killing the process.

From the docs:

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

BUILD_ID=dontKillMe /your/mongodb/process

or for pipelines:

JENKINS_NODE_COOKIE=dontKillMe /your/mongodb/process

Upvotes: 16

Ravindu Kumarasiri
Ravindu Kumarasiri

Reputation: 71

Any one facing the same problem and using pipeline project, set JENKINS_NODE_COOKIE instead of BUILD_ID.

Dont waste your time setting HUDSON_COOKIE, HUDSON_SERVER_COOKIE, JENKINS_COOKIE or JENKINS_SERVER_COOKIE. None of them work for pipeline project.

Refer to https://issues.jenkins-ci.org/browse/JENKINS-28182 for more details.

Source: https://devops.stackexchange.com/questions/1473/running-a-background-process-in-pipeline-job/1513#1513

Upvotes: 3

Dev
Dev

Reputation: 13773

As per the docs shared by @jayan,

You can disable killing processes spawned by a job during a build by setting a Java property named hudson.util.ProcessTree.disable to the value true.

This can be done as a parameter to the "java" binary when starting Jenkins:

 java -Dhudson.util.ProcessTree.disable=true -jar jenkins.war

Upvotes: 2

Related Questions