简体   繁体   English

Jenkins将变量值从Groovy脚本传递到电子邮件插件

[英]Jenkins pass the variable value from Groovy script to Email Plugin

I am trying to send one variable value from a groovy script to email plugin, so that the value will be part of email body. 我试图将一个变量值从groovy脚本发送到电子邮件插件,以便该值成为电子邮件正文的一部分。

I am using EnvInject for this, and my groovy script is as below 我为此使用EnvInject ,并且我的常规脚本如下

import hudson.model.*
def pa = new ParametersAction([
  new StringParameterValue("MYVAR", "BAR")
])
build.addAction(pa)

And in my email step in Default content section i am trying to get the value of MYVAR using the syntax ${ENV(var: "MYVAR")} Default content部分的电子邮件步骤中,我尝试使用语法${ENV(var: "MYVAR")}获取MYVAR的值

But in the email i am getting blanks. 但是在电子邮件中,我变得空白。 Please suggest what i am missing. 请提出我所缺少的。

Once you are really sure you env. 一旦您真正确定您的环境。 variable is set. 变量已设置。 You can do this: 你可以这样做:

mail bcc: '', body: "Job name: ${env.JOB_NAME} ", cc: '', charset: 'UTF-8', from: '', mimeType: 'text/html', replyTo: '', subject: "ERROR CI: Project name -> ${env.JOB_NAME}", to: "foo@foo.com";

Please, note you can access variable like this: 请注意,您可以像这样访问变量:

"${env.VAR_NAME}"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM