[英]Docker build unexpected EOF in Jenkins pipeline
我确定我不是唯一对如何处理这样的事情感兴趣的人:Jenkins管道中的docker build阶段由于意外的EOF而失败(有很多原因,在我的情况下,docker守护程序已在从属服务器上重新启动了) )
appImage = docker.build ("${projectName}:${env.BRANCH_NAME}-${gitCommit}", "--build-arg APP_ENV=${appEnv} --build-arg SKIP_LINT=true .")
部署阶段开始了,因为意外的EOF实际上并未引发任何错误,因此没有异常可以捕获,因此构建状态为null。
我知道这不是正常情况,但是我们仍然如何处理这样的问题,以免在构建被中断的情况下不进行后续操作。
其他详细信息:@JRichardsz,谢谢您的回答! 通常为currentBuild.result。 默认为null,例如https://issues.jenkins-ci.org/browse/JENKINS-46325,因此,除非在成功执行阶段后将其显式设置为成功,否则它将为null。 但是总的来说可以通过try catch来实现:
if (deployableBranches.contains(env.BRANCH_NAME)) {
try {
stage('Build image') {
ansiColor('xterm') {
appImage = docker.build
("${projectName}:${env.BRANCH_NAME}-${gitCommit}", "--build-arg
SKIP_LINT=true .")
}
}
stage('Push image') {
docker.withRegistry("${registryUrl}", "${dockerCredsId}") {
appImage.push()
appImage.push "${env.BRANCH_NAME}-latest"
}
}
stage('Deploy') {
build job: 'kubernetes-deploy', parameters: [
/////
]
}
} catch (e) {
// A shell step returns with a nonzero exit code
// When pipeline is in a shell step, and a user presses abort
if (e.getMessage().contains('script returned exit code 143')) {
currentBuild.result = "ABORTED"
} else {
currentBuild.result = "FAILED"
}
throw e
} finally {
// Success or failure or abort, always send notifications
stage('Send deployment status') {
helpers.sendDeploymentStatus(projectName, currentBuild.result,
helpers.getCommitHashShort())
}
}
}
但是问题是stage('Build image')可能会退出而没有任何错误代码,就像我的情况一样。
我有一个类似的要求:“如果在阶段A执行了某些规则,则以下阶段一定不能运行”
这为我工作:
def flag;
node {
stage('A') {
flag = 1;
}
stage('B') {
// exit this stage if flag == 1
if(flag == 1){
return;
}
//start of stage B tasks
...
}
}
您也可以使用一些jenkins变量,例如currentBuild.result,而不是像这样的标志:
node {
stage('A') {
//stage A tasks
//this stage could modify currentBuild.result variable
}
stage('B') {
// exit this stage if currentBuild.result is null , empty, "FAILURE", etc
if(currentBuild.result == null ||
currentBuild.result == "" ||
currentBuild.result=="FAILURE" ){
return;
}
//stage B tasks
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.