jenkins 通过在管道(以前称为工作流)中发送邮件来通知在不同步骤中发生的错误 [英] jenkins notifying error occured in different steps by sending mail in Pipeline (former known as Workflow)
本文介绍了jenkins 通过在管道(以前称为工作流)中发送邮件来通知在不同步骤中发生的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含多个步骤的管道,例如:
I have a pipeline with multiple steps, for example:
stage 'dev - compile'
node('master') {
//do something
}
stage 'test- compile'
node('master') {
//do something
}
stage 'prod- compile'
node('master') {
//do something
}
如果工作出现问题,我想发送一封电子邮件,无论错误在哪里触发,我如何发送电子邮件,例如:
I want to send a email if something goes wrong in the job, how can I send an email no matter where the error got triggered, something like:
try {
/**
all the code above
**/
} catch(Exception e) {
mail the error
}
推荐答案
为了在邮件中包含有关失败的有用信息,我做了什么:
What I did to include useful information in my mail about the failure:
try {
stage 'checkout cvs'
node('master') {
/** CODE **/
}
stage 'compile'
node('master') {
/** CODE **/
}
stage 'test unit'
node('master') {
/** CODE **/
}
stage 'package'
node('master') {
/** CODE **/
}
stage 'nexus publish'
node('master') {
/** CODE **/
}
stage 'Deploy to App Server'
node('master') {
/** CODE **/
}
} catch(e) {
String error = "${e}";
// Make the string with job info, example:
// ${env.JOB_NAME}
// ${env.BUILD_NUMBER}
// ${env.BUILD_URL}
// and other variables in the code
mail bcc: '',
cc: '',
charset: 'UTF-8',
from: '',
mimeType: 'text/html',
replyTo: '',
subject: "ERROR CI: Project name -> ${env.JOB_NAME}",
to: "${mails_to_notify}",
body: "<b>${pivote}</b><br>
Mensaje de error: ${error}
<br>Projecto: ${env.JOB_NAME} <br>Build Number: ${env.BUILD_NUMBER} <br> URL de build: ${env.BUILD_URL}";
error "${error}"
}
这篇关于jenkins 通过在管道(以前称为工作流)中发送邮件来通知在不同步骤中发生的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文