在 Jenkins Pipeline Mailer 中为 'recipients:' 使用环境变量
Using environment variable for 'recipients:' in Jenkins Pipeline Mailer
我在 Jenkins 环境变量 (emailsdl) 中有一个电子邮件 ID 列表,并尝试在 Jenkins Pipeline Mailer 中将其用于 recipients:
,如下所示:
mail (to: 'Mailer', recipients: '${env.emailsdl}',
subject: "Job '${env.JOB_NAME}' (${env.BUILD_NUMBER}) is waiting for input",
body: "Please go to ${env.BUILD_URL}.")
使用上面的代码我没有收到电子邮件并且收到错误消息:
Email not sent. No recipients of any kind specified ('to', 'cc', 'bcc').
但是当我用真实的电子邮件 (xyxyx@foo.com) 替换 ${env.emailsdl}
时,它确实会触发一封电子邮件。我什至尝试了 env['emailsdl']
但它没有用。
在这种情况下,有没有办法为收件人传递环境变量?
在groovy中,如果你使用单引号字符串,它不会被插入,这意味着在字符串'${env.emailsdl}'
中,变量env.emailsdl
不会被替换。您需要使用双引号字符串:"${env.emailsdl}"
@Gergely:您的建议帮助我解决了我的问题。问题是我有一个本地环境变量,它被分配了来自其他全局环境变量的值:globalVar = xyxyx@foo.com
和 emailsdl=${globalVar}
在作业的本地属性中。现在我在管道脚本中调用这个 emailsdl
。这已通过以下方式解决:
env.((env.emailsdl).replaceAll("$", ""))
我在 Jenkins 环境变量 (emailsdl) 中有一个电子邮件 ID 列表,并尝试在 Jenkins Pipeline Mailer 中将其用于 recipients:
,如下所示:
mail (to: 'Mailer', recipients: '${env.emailsdl}',
subject: "Job '${env.JOB_NAME}' (${env.BUILD_NUMBER}) is waiting for input",
body: "Please go to ${env.BUILD_URL}.")
使用上面的代码我没有收到电子邮件并且收到错误消息:
Email not sent. No recipients of any kind specified ('to', 'cc', 'bcc').
但是当我用真实的电子邮件 (xyxyx@foo.com) 替换 ${env.emailsdl}
时,它确实会触发一封电子邮件。我什至尝试了 env['emailsdl']
但它没有用。
在这种情况下,有没有办法为收件人传递环境变量?
在groovy中,如果你使用单引号字符串,它不会被插入,这意味着在字符串'${env.emailsdl}'
中,变量env.emailsdl
不会被替换。您需要使用双引号字符串:"${env.emailsdl}"
@Gergely:您的建议帮助我解决了我的问题。问题是我有一个本地环境变量,它被分配了来自其他全局环境变量的值:globalVar = xyxyx@foo.com
和 emailsdl=${globalVar}
在作业的本地属性中。现在我在管道脚本中调用这个 emailsdl
。这已通过以下方式解决:
env.((env.emailsdl).replaceAll("$", ""))