skip to Main Content

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


  1. How about you execute the command as a background process?

    http-server > /dev/null 2>&1 & 
    
    Login or Signup to reply.
  2. 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).

    Login or Signup to reply.
  3. 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 
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search