failingFast

时间:2018-11-18 03:38:09

标签: jenkins jenkins-pipeline

在声明性詹金斯管道中,在一组并行阶段中使用failFast时。如何将构建状态设置为“ FAILED”而不是“ ABORTED”?

假设出现故障,它将以“ ABORTED”退出

pipeline {
    agent any
    stages {
        stage('Parallel') {
            failFast true
            parallel {
                stage('Branch A') {
                    steps {
                        sh "foo"
                    }
                }
                stage('Branch B') {
                    steps {
                        sh "bar"
                    }
                }
                stage('Branch C') {
                    steps {
                        sh "baz"
                    }
                }
            }
        }
    }
}

如果删除FailFast,则构建最终将失败,并显示“ FAILED”。但是我也需要FailFast行为。

1 个答案:

答案 0 :(得分:1)

好的,经过一番调查,詹金斯似乎遇到了一个问题:https://issues.jenkins-ci.org/browse/JENKINS-55459

我能够通过在并行阶段的那些步骤中添加带有try / catch的脚本来实现这一目标。

steps {
     script {

          try {
               MyCode()
          }
          catch (Exception err) {
               if (currentBuild.result == null) {
                    error "The stage '${env.STAGE_NAME}' has failed."
               } else {
                    echo "Exiting stage early."
               }
           }
     }
}