emailext using groovy-html.template with environment variables issue

27 views
Skip to first unread message

amit r

unread,
Aug 7, 2019, 11:17:51 AM8/7/19
to Jenkins Users
Hi All, 
i'm using jenkinsFile and for lone time using also the emailext plugin with some default params that were ok for now..

now i reached to some issues that i want to use in my groovy html template variables that were used in my jenkinsFile  - for example env variables.

its not clear to me how can i access them within the template..
the only thing i found online is the :
build.getEnvVars() but this one also give very limited info and not on my env variables that i used in my build..

in addition , see some examples online that use project.name or build.result ... how can i know which options i have to use in this template? 


on top of it:
in the jenkinsFile it self we have this section:
emailext(
from: 'Jenkins',
replyTo: 'none',
recipientProviders: [[$class: 'CulpritsRecipientProvider'], [$class: 'DevelopersRecipientProvider'], [$class: 'RequesterRecipientProvider']],
subject: '[Jenkins] ${PROJECT_NAME} - build #${BUILD_NUMBER} - ${BUILD_STATUS}',
mimeType: 'text/html',
to: '${GERRIT_CHANGE_OWNER_EMAIL}',
body: '${SCRIPT, template="managed:groovy-html.template"}'
)

in the to: section i want to use the env variable "GERRIT_CHANGE_OWNER_EMAIL" but it not passing the value  ( i tried also with env.GERRIT_CHANGE_OWNER_EMAIL and also /${env.GERRIT_CHANGE_OWNER_EMAIL}
what is your suggestion to handle these cases?

thanks in advance!
Amit

Reinhold Füreder

unread,
Aug 8, 2019, 12:45:34 AM8/8/19
to jenkins...@googlegroups.com

Hi Amit,

 

(a) in your code/screenshot example the problem:

to: '${GERRIT_CHANGE_OWNER_EMAIL}',

[…]

in the to: section i want to use the env variable "GERRIT_CHANGE_OWNER_EMAIL" but it not passing the value  ( i tried also with env.GERRIT_CHANGE_OWNER_EMAIL and also /${env.GERRIT_CHANGE_OWNER_EMAIL}

… the problem is a Groovy one:

  • Please replace the single quotes with double quotes to allow string interpolation

 

 

(b) And in the groovy html template code there are IMHO only certain variables explicitly injected:

 

HTH Reinhold

amit r

unread,
Aug 11, 2019, 2:17:52 AM8/11/19
to Jenkins Users

Hi Reinhold, 
thank you for your help!
pls see inline

בתאריך יום חמישי, 8 באוגוסט 2019 בשעה 07:45:34 UTC+3, מאת Reinhold Füreder:

Hi Amit,

 

(a) in your code/screenshot example the problem:

to: '${GERRIT_CHANGE_OWNER_EMAIL}',

[…]

in the to: section i want to use the env variable "GERRIT_CHANGE_OWNER_EMAIL" but it not passing the value  ( i tried also with env.GERRIT_CHANGE_OWNER_EMAIL and also /${env.GERRIT_CHANGE_OWNER_EMAIL}

… the problem is a Groovy one:

  • Please replace the single quotes with double quotes to allow string interpolation

 this one worked   - tnx for that!

 

(b) And in the groovy html template code there are IMHO only certain variables explicitly injected:

 regard this part - i know these params but i'm sure that we can manipulate the template in some way to have values that no on build... for example , i have file in my workspace that contains all the values that i want to use in the mail, will it be available in the post in the template? can i import this file context into some map and use it in my email template? 

 as i know , we have already the option to run build.getEnvVars() but only for specific values that inside build context - not the env values that i'm looking for...
do you see other option for it?

 

HTH Reinhold

Reply all
Reply to author
Forward
0 new messages