catchError()设置CurrentBuild.CurrentResult时仅应设置stageresult
我有一个像这样的Jenkinsfile:
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
}
}
}
}
}
}
}
在非关键阶段
中,目标是在满足某些错误条件时不要让构建失败。但是,仅将阶段标记为不稳定
。这在詹金斯效果很好。构建结果将是成功
,即使非关键阶段
是不稳定
。但是,在中,
并行
stage CurrentBuild.CurrentResult 设置为不稳定
。
post
块是执行的最后一件事。因此,我不明白,当jenkinsfile代码的最后一个位置在jenkinsfile代码的最后位时,如何在詹金斯(Jenkins)中显示构建结果在詹金斯(Jenkins)中。
同样,当跳过非关键阶段
时,currentBuild.currentResult
是success> Success
如所预期。因此,结果为不稳定
绝对是由error()
调用引起的。
I have a Jenkinsfile like this:
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
}
}
}
}
}
}
}
In the Non-critical stage
the goal is to not let the build fail, when some error condition
is met. But to only mark the stage as UNSTABLE
. This works fine in Jenkins. The build result will be SUCCESS
, even when the Non-critical stage
is UNSTABLE
. However, in the post
block of the Parallel
stage currentBuild.currentResult
is set to UNSTABLE
.
The post
block is the last thing being executed. So I do not understand, how the build result can be shown as SUCCESS
in Jenkins, when the currentResult is UNSTABLE in the last bit of Jenkinsfile code being executed.
Also when the Non-critical stage
is skipped, currentBuild.currentResult
is SUCCESS
as expected. So the result being UNSTABLE
is definitely caused by the error()
call.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现我的问题是,后阶段并不直接在管道块的范围内。而是直接位于
阶段('Parallel')
块中。将邮政块移动后:
CurrentBuild.CurrentResult
属性正确保存值Success
I found out that my problem was, that the post stage was not directly in the scope of the pipeline block. And instead was directly in the
stage('Parallel')
block.After moving the post block down like this:
the
currentBuild.currentResult
property correctly holds the valueSUCCESS