如何在Groovy条件下使Jenkins阶段失败

zpqajqem  于 2023-04-19  发布在  Jenkins
关注(0)|答案(1)|浏览(164)

如果groovy条件为false,我希望stage失败:version ==~ versionPattern
我试过:

stage("Sanity check") {
            steps {
                script {
                    assert version !=~ versionPattern : "Build failed because git branch does not contain valid semantic version"
                }
            }

以及:

stage("Sanity check") {
            steps {
                script {
                    if(version != versionPattern) {
                        exit 1
                    }
                }
            }

我该怎么做呢?这两个例子Jenkins都忽略了

n6lpvg4x

n6lpvg4x1#

可以使用error

if(version != versionPattern) {
  error(message: "Build failed because git branch does not contain valid semantic version.")
}

相关问题