简体   繁体   中英

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.

I am using EnvInject for this, and my groovy script is as below

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")}

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}"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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