HiveBrain v1.2.0
Get Started
← Back to all entries
patternMajor

Running a background process in Pipeline job

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
backgroundprocessrunningjobpipeline

Problem

I am looking for a way to run a java process in background using Jenkins declarative pipeline. Below is the snippet of code

stage('Deploy'){
        steps{
            script{
                withEnv(['BUILD_ID=dontkill']) {
                    sh "nohup java -jar test-0.0.1-SNAPSHOT.war &"
                }
            }
        }
}


Already aware of ProcessTreeKiller of Jenkins and every answer suggest to do the same. I have tried using environment inside the steps block with no luck.

Jenkins version : 2.60.1

Pipeline plugin : 1.1.7

Any help is greatly appreciated.

Solution

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.

Context

StackExchange DevOps Q#1473, answer score: 21

Revisions (0)

No revisions yet.