我正在使用Jenking DSL Plugin / Groovy在作业成功后发送电子邮件。
Chart(df).mark_bar().encode(y=Y('values', axis=Axis(grid=False)),
x='c2:N',
column=Column('c1:N') ,
color='DF:N').configure_facet_cell( strokeWidth=0.0).configure_cell(width=200, height=200)
在内容部分
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}")
}
}
}
}
}
}
如果我使用单引号然后我能够打印日志作为电子邮件的内容,但也不能打印作业名称,如果我使用双引号,那么我能够打印作业名称,但不能打印构建日志。
如何在电子邮件中打印作业名称和构建日志?
答案 0 :(得分:1)
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>")