gpt4 book ai didi

email - 从 Jenkins 作业发送构建日志作为电子邮件的内容

转载 作者:行者123 更新时间:2023-12-04 03:11:30 26 4
gpt4 key购买 nike

作业成功运行后,我正在使用 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>')

如果我使用单引号,那么我可以打印日志作为电子邮件的内容,但也不能打印作业名称,如果我使用双引号,那么我可以打印作业名称,但不能打印构建日志。

如何在电子邮件中打印作业名称和构建日志?

最佳答案

String interpolation仅适用于双引号字符串,因此请将引号更改为双引号。

当您说 BUILD_LOG 扩展之后不起作用时,是因为 var 不是由 Groovy 扩展的,而是由 Jenkins 本身扩展的。所以请尝试以下操作:

content("See the latest build in the jenkins job here https://jenkins.xyz.com/job/${jobName}/ " + '<pre> ${BUILD_LOG, maxLines=30, escapeHtml=false} </pre>')

或者你转义$:

content("See the latest build in the jenkins job here https://jenkins.xyz.com/job/${jobName}/ <pre> \${BUILD_LOG, maxLines=30, escapeHtml=false} </pre>")

关于email - 从 Jenkins 作业发送构建日志作为电子邮件的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44939253/

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