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
3
Answers
How about you execute the command as a background process?
Don’t use CtrlC, but use CtrlZ – or use
&
to detach the console (second option is better for scripting).On Jenkins you might also want to obtain the PID of that process, in order to kill it again; else you’ll spawn a new process with every single build. Setting up Apache or Ngnix might provide a more reliable experience; else you’ll have to mess around with PID, instead of just deploying (the script will ultimately not run on
http-server
anyway).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.
A similar environment variable is required for Pipeline projects.
If you want to globally disable this feature you can use the following Java system property
More recently, the Jenkins Project documentation recommends using a daemon wrapper in conjunction with the appropriate environment variable.
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.