title: How to deploy Java war file using Jenkinsfile in jenkins pipeline
body: <p>In jenkins maven project we can use <code>BUILD_ID=DontKillMe</code> to prevent hudson script shutdown the shell calls.</p>
  
  <p>Like: <code>BUILD_ID=DontKillMe java -jar target.jar</code></p>
  
  <p><strong>But add <code>BUILD_ID</code> is not work in <code>Jenkinsfile</code>.</strong></p>
  
  <hr>
  
  <p>Jenkinsfile:</p>
  
  <pre><code>#!/usr/bin/env groovy
  
  node {
      stage('Build') {
          checkout scm
          sh '/opt/gradle/gradle-4.1/bin/gradle clean build'
      }
      stage('Deploy') {
          sh 'mkdir -p /opt/www/foobar'
          sh 'cp build/libs/*.war /opt/www/foobar/newest.war'
          sh 'chmod 755 ./deploy.sh'
          sh 'nohup ./deploy.sh &amp;'
          sh 'while ! httping -qc1 http://localhost:10000 ; do sleep 1 ; done'
      }
  }
  </code></pre>
  
  <p>After hudson script executed, all the shells called by hudson script would be shutdown. <strong>Even double <code>nohup</code> still not work.</strong></p>
  
  <p>deploy.sh:</p>
  
  <pre><code>#!/bin/bash
  
  nohup java -jar -Dspring.profiles.active=prod /opt/www/foobar/newest.war /var/log/foobar.log 2&gt;&amp;1 &amp;
  </code></pre>