Jenkins:将用户定义的变量传递给Email-Ext插件 [英] Jenkins: Passing user defined variables to Email-Ext plugin
问题描述
我正在使用Email-Ext插件在声明式管道的后期构建阶段的构建结束时发送结果电子邮件.在电子邮件的正文中,我尝试插入一些环境变量和一些用户定义的环境变量.
I'm using the Email-Ext plugin to send a results email at the end of my build in the post build stage of a declarative pipeline. In the body of the email I'm trying to insert some environment variables and some user defined environment variables.
内置变量显示良好,但是我定义的任何用户定义变量在电子邮件正文中都为空,或者在attachmentPattern字段中也不起作用:
The built in variables show up fine, however any user defined variables I define are just empty in the body of the email or don't work in the attachmentPattern field either:
我的环境变量:
pipeline {
agent any
environment {
buildFolder = "build_${BUILD_NUMBER}"
robotFolder = "build_${BUILD_NUMBER}/robotDemo"
serverName = "abc123"
robotResults = "${buildFolder}/*.txt"
}
我在帖子中使用的email-ext格式{}版本:
The email-ext format I am using in my post{} build:
emailext attachLog: true, attachmentsPattern: 'build_${env.BUILD_NUMBER}/Robot_Results.txt', body: '<b>Job Name:</b> ${ENV, var="JOB_NAME"}<br><b>Build Number:</b> ${ENV, var="BUILD_NUMBER"}<br><br><b>Build URL:</b><br>${ENV, var="BUILD_URL"}<br><br><b>Log Files:<br><br><br><pre>${BUILD_LOG_EXCERPT, start="^====", end="^report.html"}</pre><pre>${ENV, var="serverName"}</pre>', mimeType: 'text/html', subject: 'ABS Results', to: 'richard.scott@sap.com'
例如:$ {ENV,var ="JOB_NAME"},显示正常.但是$ {ENV,var ="serverName"}根本不显示.
For example: ${ENV, var="JOB_NAME"}, shows up fine. However ${ENV, var="serverName"} doesn't show at all.
我尝试了诸如...
$ {serverName}
$ {env.serverName}
...但是它们也不起作用.
...but they don't work either.
有什么想法如何在email-ext插件中使用用户定义的环境变量,例如上面的"serverName"?
Any ideas how to use user defined environment variables like 'serverName' above in the email-ext plug-in?
感谢&最好的问候,理查德.
Thanks & best regards, Richard.
推荐答案
您使用的是单引号,但只有双引号允许对变量进行插值.
You’re using single quotes, but only double quotes allow variables to be interpolated.
我建议您使用Groovy脚本来呈现电子邮件内容.
I would suggest you to use a Groovy script for rendering the email contents.
您可以使用
或添加自己的模板,如文档中所述 .我无法确定是否可以从工作空间中加载该模板,但是您可以尝试以下操作: Or add your own template like described in the documentation. I couldn't figure our if it's possible to load that template from the workspace, but you could try it with: 在插值时从环境或参数获取值的语法为: The syntax for getting values from the environment or parameters when interpolating is: (env和param是保存所有值的ja Groovy映射) (env and param is ja Groovy map holding all the values) 对于所有其他变量: 这篇关于Jenkins:将用户定义的变量传递给Email-Ext插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!emailext body: '''${SCRIPT, template="$WORKSPACE/groovy-html.template"}'''
${env.MY_ENVVAR}
${param.MY_BUILDPARAM}
${varName}