gpt4 book ai didi

jenkins - 发送有关 Jenkins 管道故障的电子邮件

转载 作者:行者123 更新时间:2023-12-02 05:30:20 28 4
gpt4 key购买 nike

如何向 Jenkins 管道添加一个旧式的构建后任务,该任务在构建失败时发送电子邮件?我在管道的 GUI 中找不到“构建后操作”。我知道我可以包装整个构建脚本 try/catch,但是,当构建脚本很大并且即使手动中止作业也继续发送电子邮件时,这看起来很丑陋。我希望实现与之前基于 email-ext 的构建后操作相同的功能。

try {
// Do sth
} catch(e) {
emailext body: '$DEFAULT_CONTENT',
recipientProviders: [
[$class: 'CulpritsRecipientProvider'],
[$class: 'DevelopersRecipientProvider'],
[$class: 'RequesterRecipientProvider']
],
replyTo: '$DEFAULT_REPLYTO',
subject: '$DEFAULT_SUBJECT',
to: '$DEFAULT_RECIPIENTS'
throw err
}

最佳答案

这个答案适用于我的 Jenkins 版本。 2.96。

Jenkins pipeline email not sent on build failure - Stack Overflow

 pipeline {  
agent any
stages {
stage('Test') {
steps {
sh 'echo "Fail!"; exit 1'
}
}
}
post {
always {
echo 'This will always run'
}
success {
echo 'This will run only if successful'
}
failure {
mail bcc: '', body: "<b>Example</b><br>Project: ${env.JOB_NAME} <br>Build Number: ${env.BUILD_NUMBER} <br> URL de build: ${env.BUILD_URL}", cc: '', charset: 'UTF-8', from: '', mimeType: 'text/html', replyTo: '', subject: "ERROR CI: Project name -> ${env.JOB_NAME}", to: "foo@foomail.com";
}
unstable {
echo 'This will run only if the run was marked as unstable'
}
changed {
echo 'This will run only if the state of the Pipeline has changed'
echo 'For example, if the Pipeline was previously failing but is now successful'
}
}
}

Official documentation for the mail step

关于jenkins - 发送有关 Jenkins 管道故障的电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39720225/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com