如果测试返回失败或不稳定,我想将整个构建标记为失败。我认为这样做就足够了:
currentBuild.result = 'FAILURE'
它几乎可以工作。在 Jenkins 控制台我可以看到
Finished: FAILURE
整个管道都标有红色,但是当我将鼠标移到它上面时,它显示状态为成功:
我想获得状态为“失败”而非“成功”的信息。 您可以在下面查看我的代码:
stage('Run tests') {
boolean currentBuildUnstable = false
parallel("Test 1": {
def result = build job: 'test-1-job', propagate: false
currentBuildUnstable = currentBuildUnstable || isUnstable(result)
},"Test 2": {
def result = build job: 'test-2-job', propagate: false
currentBuildUnstable = currentBuildUnstable || isUnstable(result)
},
failFast: true
)
if(currentBuildUnstable) {
node('master') {
currentBuild.result = 'FAILURE'
}
}
}
最佳答案
好的,我设法解决了这个问题。我创建了额外的阶段,在这个阶段中我将构建视为失败。我的代码现在看起来像这样:
boolean currentBuildUnstable = false
stage('Run tests') {
parallel("Test 1": {
def result = build job: 'test-1-job', propagate: false
currentBuildUnstable = currentBuildUnstable || isUnstable(result)
},"Test 2": {
def result = build job: 'test-2-job', propagate: false
currentBuildUnstable = currentBuildUnstable || isUnstable(result)
},
failFast: true
)
}
if(currentBuildUnstable) {
stage('Check') {
node('master') {
currentBuild.result = 'FAILURE'
}
}
}
但是,我不知道为什么以前的代码没有按预期工作。
关于jenkins - 让 Jenkins 建立失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44023967/