sem*_*ral 3 jenkins jenkins-groovy jenkins-declarative-pipeline
使用 Jenkins声明式 管道检查前一阶段是否失败的最佳方法是什么,如果失败则运行回滚命令。
我只是尝试如下,但它抛出如下错误。
不允许脚本使用 org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper getRawBuild 方法。管理员可以决定是否批准或拒绝此签名。
stage('Deploy to production'){
when{
beforeAgent true
expression{return env.GIT_BRANCH == "origin/master"}
}
steps{
script{
echo "Deploying production environment"
sh "helm install ...."
}else {
error "Buid was not confirmed"
}
stage('Roll Back'){
when{
expression {
!hudson.model.Result.SUCCESS.equals(currentBuild.rawBuild.getPreviousBuild()?.getResult()) == true
}
}
steps{
script{
sh "helm rollback <release> 0"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
小智 10
您可以使用!("SUCCESS".equals(currentBuild.previousBuild.result))。
似乎rawBuild仅限于受信任的库(全局定义的库),或者您需要向该方法添加例外。
但.previousBuild直接使用应该可以。
https://opensource.triology.de/jenkins/pipeline-syntax/globals