Reputation: 2492
I am trying to keep a web process running after the Jenkins job is done.
I looked into ProcessTreeKiller and have tried using BuildId
as below, but it doesn't seem to work:
BUILD_ID=dontKillMe /usr/apache/bin/httpd
My command (which I want to keep it running):
rails s &
How can I fix this issue ?
Upvotes: 6
Views: 10357
Reputation: 29
If it is the last stage in your Jenkinsfile, (like my case), you can use BUILD_ID=dontKillMe
to solve that problem, like this:
stage("Run"){
steps{
withEnv(['BUILD_ID=dontKillMe']) {
script{
sh '<YOUR COMMAND HERE>'
}
}
}
}
In my case, I have Jenkins in Ubuntu, and I want to run the last stage of my jenkinsfile forever, so I used :
stage("Run app service forever"){
steps{
withEnv(['BUILD_ID=dontKillMe']) {
script{
kubeconfig(credentialsId: 'my_minikube_config_file', serverUrl: 'https://###.###.###.###:8443') {
sh 'kubectl port-forward --address 0.0.0.0 services/tecapp 5000:5000'
}
}
}
}
}
NB: DON'T add & at the end of your command, like this :
stage("Run"){
steps{
withEnv(['BUILD_ID=dontKillMe']) {
script{
sh '<YOUR COMMAND HERE> &'
}
}
}
}
when I used &, the stage didn't run forever.
Upvotes: 0
Reputation: 19016
Try with:
(
set -e
export BUILD_ID=dontKillMe
export JENKINS_NODE_COOKIE=dontKillMe
rails &
) &
Upvotes: 2
Reputation: 59
start jenkin server by
java -Dhudson.util.ProcessTree.disable=true -jar jenkins.war --httpPort=8090
code to be in jenkinfile which goes in background
stage("Starting API Server"){
withEnv(['BUILD_ID=dontkill']) {
sh 'mvn exec:java -Dexec.mainClass="APPLICATION_SERVER.App" & '
}
}
Upvotes: -2
Reputation: 27515
You put that into your Execute Shell build step, not as a jenkins build process variable (which is what you did with EnvInject plugin in your screenshot)
So, if you are trying to run rails &
, then do:
BUILD_ID=dontKillMe rails &
Upvotes: 6