在jenkins maven项目中,我们可以使用BUILD_ID=DontKillMe
来阻止hudson脚本关闭shell调用。如何在jenkins管道中使用Jenkinsfile部署Java war文件
像:BUILD_ID=DontKillMe java -jar target.jar
但添加BUILD_ID
不Jenkinsfile
工作。
Jenkinsfile:
哈德森脚本执行#!/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 &'
sh 'while ! httping -qc1 http://localhost:10000 ; do sleep 1 ; done'
}
}
后,全部由哈德森脚本调用炮弹将被关闭。 即使是双重nohup
仍然无法正常工作。
deploy.sh:
#!/bin/bash
nohup java -jar -Dspring.profiles.active=prod /opt/www/foobar/newest.war /var/log/foobar.log 2>&1 &
它在管道的'Jenkinsfile'构建脚本中没用。 –
@SuCheung它应该工作。但它似乎有一个错误,当它在某些操作系统上不起作用时https://issues.jenkins-ci.org/browse/JENKINS-46481 –
了解,但我总是觉得'BUILD_ID = dontKillMe'很脏。 –