我有一个这样的詹金斯档案:
pipeline {
agent any
stages {
stage('Parallel') {
parallel {
stage('Non-critical stage') {
steps {
script {
// Other steps...
if (/*some error condition*/) {
catchError(buildResult: null, stageResult: 'UNSTABLE') {
// Fail only the stage, but leave the buildResult as is
error("Error message")
}
}
}
}
}
stage('critical stage') {
steps {
// a different stage that really matters
}
}
}
post {
always {
script {
if (currentBuild.currentResult != 'SUCCESS') {
// When the Non-critical stage fails, the currentResult is UNSTABLE...
// ...even though only the stageResult should have been set.
// However, in the Jenkins UI the build result is SUCCESS
}
}
}
}
}
}
}在Non-critical stage中,目标是当some error condition满足时,不要让构建失败。但只将舞台标记为UNSTABLE。这在詹金斯很好。构建结果将是SUCCESS,即使Non-critical stage是UNSTABLE。但是,在post阶段的Parallel块中,currentBuild.currentResult设置为UNSTABLE。
post块是执行的最后一件事。因此,我不明白如何在Jenkins中将构建结果显示为SUCCESS,而在正在执行的Jenkinsfile代码中,currentResult是不稳定的。
同样,当跳过Non-critical stage时,currentBuild.currentResult也是SUCCESS。因此,UNSTABLE的结果肯定是由error()调用引起的。
发布于 2022-05-23 07:54:53
我发现我的问题是,后阶段不是直接在管道阻塞的范围内。而是直接出现在stage('Parallel')块中。
在像这样移动了后座之后:
pipeline {
agent any
stages {
stage('Parallel') {
parallel {
stage('Non-critical stage') {
steps {
script {
// Other steps...
if (/*some error condition*/) {
catchError(buildResult: null, stageResult: 'UNSTABLE') {
// Fail only the stage, but leave the buildResult as is
error("Error message")
}
}
}
}
}
stage('critical stage') {
steps {
// a different stage that really matters
}
}
}
}
}
post {
always {
script {
if (currentBuild.currentResult != 'SUCCESS') {
// Now the currentResult is 'SUCCESS'
}
}
}
}
}currentBuild.currentResult属性正确地保存值SUCCESS。
https://stackoverflow.com/questions/72285290
复制相似问题