这是我前面的问题的后续内容:
Set a stage status in Jenkins Pipelines
事实证明,如果我想通过catchError
进行如下操作,我可以将管道保持为SUCCESS,但可以将单个阶段标记为UNSTABLE:
node()
{
stage("Stage 1")
{
catchError(buildResult: 'SUCCESS',stageResult: 'UNSTABLE')
{
sh 'exit 1'
}
}
}
如果我想获取管道本身的当前状态,可以使用currentBuild.getcurrentResult()
,但看不到与此类似的currentStage
。
我有兴趣尝试一种可能在我的阶段看起来像这样的模式:
stage("1") {
catchError(buildResult: 'SUCCESS',stageResult: 'UNSTABLE') {
// do stuff
}
// perhaps more catchError() blocks
if(currentStage.getcurrentResult() == "UNSTABLE") {
// do something special if we're unstable
}
}
但这会失败,因为没有currentStage
可用。
因此,catchError()
基本上不错,但是我想知道如果更改后如何将状态更改捕获到我的阶段...有人知道您如何访问当前阶段的状态吗?从管道进入吗?