如何在执行过程中跳过 Jenkins 阶段?一旦确定了跳过条件,这就像在某些步骤之后或在步骤中间使用
when
一样。我知道我可以进一步分解阶段/步骤并使用全局变量来实现此目的,但似乎应该有一种更简单的方法。
该步骤应显示为已跳过,而不是失败或不稳定。
stage('Builds') {
failFast true
parallel {
stage('FlagA') {
steps {
BuildWithFlag("FlagA")
}
}
stage('FlagB') {
steps {
BuildWithFlag("FlagB")
}
}
...
void BuildWithFlag(String flag) {
skipCondition = false
<setup-steps>
if(skipCondition) {
currentStage.result = '' // Doesn't work
return
}
<build-steps>
}
相关:
Jenkins 管道中的条件步骤/阶段
如何在声明性管道中执行when..else
Jenkins 管道阶段跳过基于管道中定义的 groovy 变量
所有这些都在阶段开始时使用
when
。我需要在一个步骤中模仿它。
您想将舞台设置为
"NOT_BUILT"
。这是使用 when
跳过的步骤的状态。
例如
if(skipCondition) {
catchError(buildResult: 'SUCCESS', stageResult: 'NOT_BUILT') {
error "Skipping..." // Force an error that we will catch to set the stageResult
}
return
}