我正在运行Jenkins声明式管道,它共有10个阶段。我的要求是,如果出现任何阶段故障,则中止构建。我正在使用以下脚本,尽管它的工作管道因以下错误而中止。
执行故障后条件时出错: hudson.AbortException:脚本返回了退出代码1 在org.jenkinsci.plugins.workflow.steps.durable_task.DurableTaskStep $ Execution.handleExit(DurableTaskStep.java:658)
def PYTHON_BUILD;
def disagg_py;
pipeline {
agent any
stages {
stage('version'){
steps{
script {
disagg_py = build(
job: 'version',
)
}
println 'Jenkins version:'
script {
PYTHON_BUILD = 'PROD_PYAMIDISAGG_1.0.'+disagg_py.displayName
PYTHON_BUILD = PYTHON_BUILD.replace("#", "");
println PYTHON_BUILD
}
}
post {
failure {
emailext body: 'A Test EMail', recipientProviders: [[$class: 'DevelopersRecipientProvider'], [$class: 'RequesterRecipientProvider']], subject: 'Test'
script{
sh "exit 1"
}
}
}
}
stage('docker version'){
steps{
retry(3) {
build job : 'version2'
}
}
post {
failure {
emailext body: 'A Test EMail', recipientProviders: [[$class: 'DevelopersRecipientProvider'], [$class: 'RequesterRecipientProvider']], subject: 'Test'
}
}
}
}
}
```
答案 0 :(得分:0)
您可以使用error
步骤:
error('Build has failed.')