title: How to fork a background process in Jenkins? Setting BUILD_ID and using nohup seems to be non working
body: <p>I have a maven job in Jenkins(version 1.578). The maven snippet (Ant script written in Groovy code) below starts a Fuse server, and I cannot make Jenkins to leave it running after the job finishes.</p>
  
  <pre><code>&lt;profile&gt;
      &lt;id&gt;start-fuse&lt;/id&gt;
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.codehaus.gmaven&lt;/groupId&gt;
                  &lt;artifactId&gt;gmaven-plugin&lt;/artifactId&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;id&gt;start-fuse&lt;/id&gt;
                          &lt;phase&gt;integration-test&lt;/phase&gt;
                          &lt;goals&gt;
                            &lt;goal&gt;execute&lt;/goal&gt;
                          &lt;/goals&gt;
                          &lt;configuration&gt;
                              &lt;source&gt;
                              &lt;![CDATA[
                                  def fuseBinDirectory = '${fuse.dir}/bin'
                                  ant.exec(executable:'bash', dir:fuseBinDirectory, failonerror:true, osfamily:'unix') {
                                      ant.env(key:'BUILD_ID',value:'DO_NOT_STOP_MY_PROCESS_JENKINS')
                                      ant.env(key:'KARAF_OPTS',value:'${KARAF_OPTS}')
                                      ant.arg(value:"-c")
                                      ant.arg(value:"nohup ./start ${fuse.start.parameters} &lt;/dev/null &gt;&gt; nohup.out 2&gt;&amp;1&amp;")
                                  }
                              ]]&gt;
                              &lt;/source&gt;
                          &lt;/configuration&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  &lt;/profile&gt;
  </code></pre>
  
  <p>What do I wrong?</p>
  
  <p>How can I fork a similar Fuse process under Windows so that Jenkins does not kill it?</p>
  
  <h2>UPDATE - SOLUTION</h2>
  
  <p>Adding the 4 env entries mentioned in the accepted answer works both on windows and linux. So no matter which job type you have you can have something like this:</p>
  
  <pre><code>ant.exec(executable:'sh', dir:fuseBinDirectory, failonerror:true, osfamily:'unix') {
      ant.env(key:'BUILD_ID',value:'DO_NOT_STOP_MY_PROCESS_JENKINS')
      ant.env(key:'HUDSON_SERVER_COOKIE',value:'DO_NOT_STOP_MY_PROCESS_JENKINS')
      ant.env(key:'JENKINS_COOKIE',value:'DO_NOT_STOP_MY_PROCESS_JENKINS')
      ant.env(key:'JENKINS_SERVER_COOKIE',value:'DO_NOT_STOP_MY_PROCESS_JENKINS')
      ant.env(key:'HUDSON_COOKIE',value:'DO_NOT_STOP_MY_PROCESS_JENKINS')
      ant.env(key:'KARAF_OPTS',value:'${KARAF_OPTS}')
      ant.arg(line:'-c "./start ${fuse.start.parameters}"')
  }
  </code></pre>
  
  <p>Nohup seems to be non neccessary at all.</p>