声明性管道:如果构建被禁止,则不发送帖子/失败通知

时间:2017-03-23 10:32:49

标签: jenkins jenkins-pipeline

我正在尝试设置声明性管道故障的通知,如下所述:
https://jenkins.io/doc/pipeline/tour/post/

post {
    failure {
        emailext (
            subject: "FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
            body: """<p>FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':</p>
                <p>Check console output at &QUOT;<a href='${env.BUILD_URL}'>${env.JOB_NAME} [${env.BUILD_NUMBER}]</a>&QUOT;</p>""",
            recipientProviders: [[$class: 'CulpritsRecipientProvider']]
        )
       }
    }
}

如果构建中止,有没有办法不发送电子邮件?

在“旧”脚本管道中,我捕获了FlowInterruptedException来实现此目的。

catch (org.jenkinsci.plugins.workflow.steps.FlowInterruptedException e) {
    echo "the job was cancelled or aborted"
    currentBuild.result = 'ABORTED'    
}

1 个答案:

答案 0 :(得分:5)

https://issues.jenkins-ci.org/browse/JENKINS-43339已修复此问题 有一个错误将currentBuild.result设置为FAILURE而不是ABORTED。

确保在更新后重新启动jenkins。

相关问题