【发布时间】:2022-08-04 20:41:07
【问题描述】:
如果我有一个允许单个阶段失败的管道,而不会使整个工作失败,我该如何添加错误处理,例如,当该阶段失败时向管理员发送电子邮件?我试过使用postfailure,但它不起作用。
pipeline {
agent any
stages {
stage(\'1\') {
steps {
sh \'exit 0\'
}
}
stage(\'2\') {
steps {
catchError(buildResult: \'SUCCESS\', stageResult: \'FAILURE\') {
sh \"exit 1\"
}
}
post {
failure {
echo \'Sending email to admin...\'
}
}
}
stage(\'3\') {
steps {
sh \'exit 0\'
}
}
}
}
我在comment 中收到了这个问题,并认为这是一个值得提出和回答的正确问题。