Issue
I want to run the command http-server command on jenkins. It is a command which runs continusly it will never gets disconnected until we do the CTRL+C. What happens is the job is failed since the commmand never completes. Any solution. I want the server to run and jenkins job to be succeeded any solution??
UPDATE: I made a script using os library in python and configured the commands over there and run that script this worked for me
Solution
Jenkins ProcessTreeKiller
Any process resulting from a command executed within a Jenkins Job or Pipeline will be a child process of the respective Jenkins build node. Jenkins, by design, kills all child processes spawned by a build once the build completes.
This feature is called ProcessTreeKiller. For Freestyle Jobs the Jenkins documentation has traditionally recommended setting the following environment variable in an Execute Shell step of your job.
export BUILD_ID=dontKillMe
A similar environment variable is required for Pipeline projects.
export JENKINS_NODE_COOKIE=dontKillMe
If you want to globally disable this feature you can use the following Java system property
java -Dhudson.util.ProcessTree.disable=true -jar jenkins.war
More recently, the Jenkins Project documentation recommends using a daemon wrapper in conjunction with the appropriate environment variable.
daemonize -E BUILD_ID=dontKillMe http-server
If none of the aforementioned options is suitable for your particular use case you could develop your Jenkins project to publish a message to a message queue. You could then have a consumer running as a service that consumes your message and executes a command based on the message instructions.
Post Script
A concern was raised in the comments about modifying the BUILD_ID environment variable in a Freestyle Job.
While this is undocumented and likely deprecated, I believe you may use the following environment variable to prevent the ProcessTreeKiller from killing your Freestyle Job’s child processes.
export JENKINS_SERVER_COOKIE=dontKillMe
Answered By - Chris Maggiulli Answer Checked By - David Marino (WPSolving Volunteer)