Hi, I am trying to start a background process by running a shell script from the jenkins jobs. The problem is as soon as the job completes the background job is getting killed. I have tried running it with nohup as well as by giving parameter “BUILD_ID=dontKillMe” but it didn’t work.
It will be a big help if someone could guide me on this.
Jenkins kills all processes started by job once the job is finished to avoid that you have runaway processes.
Starting background jobs from Jenkins is not the right approach I think because when the job runs multiple times it will try to start the daemon multiple times. So you would need to find a way to reliable kill the background process once the Jenkins job runs again.
Technically it is possible to stop Jenkins from killing the daemon process https://wiki.jenkins.io/display/JENKINS/ProcessTreeKiller
Just don’t pass it as a job parameter and for pipeline jobs you have to use JENKINS_NODE_COOKIE instead of BUILD_ID
Are you doing this in a pipeline job or a freestyle job?
Can you share the script that you run?
e.g. in a pipeline script you should do something like this:
sh '''
JENKINS_NODE_COOKIE=dontKillMe /mybackgroundexecutable &
'''
It didn’t worked. Alternatively when I tried to run above command without nohup the jenkins job is running indefinitely. Its like I am stuck in an infinite loop.