如何在执行Jenkins的某些步骤(如when指令)后跳过它?

vlju58qv  于 8个月前  发布在  Jenkins
关注(0)|答案(1)|浏览(100)

如何在Jenkins stage执行的中途跳过它?这就像在一些步骤之后或在一个步骤的中间使用when,一旦跳过条件已经确定。我知道我可以进一步分解stages/steps并使用全局变量来实现这一点,但似乎应该有一个更简单的方法。

该步骤应该显示为跳过,而不是失败或不稳定。

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>
}

字符串
相关:
Conditional step/stage in Jenkins pipeline
How to perform when..else in declarative pipeline
Jenkins Pipeline stage skip based on groovy variable defined in pipeline
所有这些都在阶段开始时使用when。我需要在一个步骤的中途模仿它。

bfnvny8b

bfnvny8b1#

您希望将阶段设置为"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
}

字符串

相关问题