一旦作业成功运行,我正在使用 Jenking DSL 插件/Groovy 发送电子邮件。
static void sendEmail(Job job, String jobName) {
job.with {
publishers {
extendedEmail {
recipientList('xyzcoders@xyz.com')
defaultSubject("Jenkins Job started : ${jobName}")
defaultContent("See the latest build in the jenkins job here https://jenkins.xyz.com/job/${jobName}/")
contentType('text/html')
triggers {
failure {
content("See the latest build in the jenkins job here https://jenkins.xyz.com/job/${jobName}/")
contentType('text/html')
recipientList('xyzcoder@xyz.com')
subject("Build Failed in Jenkins: ${jobName}")
}
success {
content('See the latest build in the jenkins job here https://jenkins.xyz.com/job/${jobName}/ <pre> ${BUILD_LOG, maxLines=30, escapeHtml=false} </pre>')
contentType('text/html')
recipientList('xyzcoder@xyz.com')
subject("Build Success in Jenkins: ${jobName}")
}
}
}
}
}
}
在内容部分
content('See the latest build in the jenkins job here https://jenkins.xyz.com/job/${jobName}/ <pre> ${BUILD_LOG, maxLines=30, escapeHtml=false} </pre>')
如果我使用单引号,那么我可以打印日志作为电子邮件的内容,但也不能打印作业名称,如果我使用双引号,那么我可以打印作业名称,但不能打印构建日志。
如何在电子邮件中同时打印作业名称和构建日志?