louisatome
louisatome

Reputation: 75

Jenkins launch application on slave

I try to launch my built application on my OSX slave from Jenkins but at the end of my stage, Jenkins seems to kill the process of my app. The declarative pipeline I use is :

stage('install-osx') {
  agent { label 'OSX dev' }
  steps {
    unstash 'app-osx'
    sh 'hdiutil attach bin/target/MyApp.dmg'
    sh 'rm -rf /tmp/MyApp.app/'
    sh 'cp -R /Volumes/MyApp/MyApp.app /tmp/'
    sh 'nohup open /tmp/MyApp.app &'
    sleep 10
    sh 'hdiutil detach /Volumes/MyApp'
    sh 'echo "END"'
  }
}

My application is launch without problem but as soon as the stage ends, the process is killed. I've try with/without the nohup and with/without the final '&' without success, the behaviour is always the same.

Edit:

I needed to set the JENKINS_NODE_COOKIE env variable to tell Jenkins not to kill my spawn process after the end of the stage :

stage('install-osx') {
  agent { label 'OSX dev' }
  steps {
    withEnv(["JENKINS_NODE_COOKIE=dontKillMe"]) {
      unstash 'app-osx'
      sh 'hdiutil attach bin/target/MyApp.dmg'
      sh 'rm -rf /tmp/MyApp.app/'
      sh 'cp -R /Volumes/MyApp/MyApp.app /tmp/'
      sh 'nohup open /tmp/MyApp.app &'
      sleep 10
      sh 'hdiutil detach /Volumes/MyApp'
      sh 'echo "END"'
   }
  }
}

Upvotes: 1

Views: 489

Answers (1)

pitseeker
pitseeker

Reputation: 2563

That's the intended behaviour.
At the end of a job Jenkins kills any left over process that was spawned by the job.

It is also possible to disable this feature - see ProcessTreeKiller. AFAIK this is only possible for the whole of the Jenkins instance - not just for specific jobs.

It is probably a good idea that you reconfigure your job so that it does all of its work before finishing, so that no left over processes remain.

Upvotes: 2

Related Questions