Jenkins管道电子邮件在构建失败时未发送 [英] Jenkins pipeline email not sent on build failure
本文介绍了Jenkins管道电子邮件在构建失败时未发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在管道詹金斯工作中使用以下步骤:
I am using following step in my pipeline jenkins job:
step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: 'my@xyz.com', sendToIndividuals: true])
但是在构建失败(即错误)时没有发送电子邮件.任何指针为什么?
But no email was sent when the build failed (i.e. error). Any pointers why?
P.S.可以从此服务器发送电子邮件,我已经对此进行了测试.
P.S. Emails can be sent from this server, I have tested that.
推荐答案
使用新语法使用声明性管道,例如:
Use Declarative Pipelines using new syntax, for example:
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>\n\<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'
}
}
}
您可以在詹金斯官方网站上找到更多信息:
You can find more information in the Official Jenkins Site:
https://jenkins.io/doc/pipeline/tour/running -multiple-steps/
请注意,这种新语法使您的管道更具可读性,逻辑性和可维护性.
Note that this new syntax make your pipelines more readable, logic and maintainable.
这篇关于Jenkins管道电子邮件在构建失败时未发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文