emailext using groovy-html.template with environment variables issue

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

emailext using groovy-html.template with environment variables issue

amit r
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

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/a788acb9-f1c2-4cc1-98b9-6437195c315d%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

RE: emailext using groovy-html.template with environment variables issue

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

 

 

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

 

HTH Reinhold

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/AM0PR01MB6147232554C60333C07B17DDF7D70%40AM0PR01MB6147.eurprd01.prod.exchangelabs.com.
Reply | Threaded
Open this post in threaded view
|

Re: emailext using groovy-html.template with environment variables issue

amit r

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:

  • Based upon <a href="http://stackoverflow.com/a/9983405" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fstackoverflow.com%2Fa%2F9983405\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHA7f_5T3MtPrtpKxU096MFf6Zuvw&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fstackoverflow.com%2Fa%2F9983405\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHA7f_5T3MtPrtpKxU096MFf6Zuvw&#39;;return true;">http://stackoverflow.com/a/9983405 and <a href="https://github.com/jenkinsci/email-ext-plugin/blob/master/src/main/java/hudson/plugins/emailext/plugins/content/ScriptContent.java" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkinsci%2Femail-ext-plugin%2Fblob%2Fmaster%2Fsrc%2Fmain%2Fjava%2Fhudson%2Fplugins%2Femailext%2Fplugins%2Fcontent%2FScriptContent.java\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGDQ20DQ_lqBRVqvn7KBTrNZ1GwHA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkinsci%2Femail-ext-plugin%2Fblob%2Fmaster%2Fsrc%2Fmain%2Fjava%2Fhudson%2Fplugins%2Femailext%2Fplugins%2Fcontent%2FScriptContent.java\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGDQ20DQ_lqBRVqvn7KBTrNZ1GwHA&#39;;return true;">https://github.com/jenkinsci/email-ext-plugin/blob/master/src/main/java/hudson/plugins/emailext/plugins/content/ScriptContent.java please note the “binding.put(...)” calls, e.g.:
    • build ... <a href="http://javadoc.jenkins.io/plugin/workflow-job/org/jenkinsci/plugins/workflow/job/WorkflowRun.html" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fjavadoc.jenkins.io%2Fplugin%2Fworkflow-job%2Forg%2Fjenkinsci%2Fplugins%2Fworkflow%2Fjob%2FWorkflowRun.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEWtixZDjBqJYjfOQk1IBX003PxJg&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fjavadoc.jenkins.io%2Fplugin%2Fworkflow-job%2Forg%2Fjenkinsci%2Fplugins%2Fworkflow%2Fjob%2FWorkflowRun.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEWtixZDjBqJYjfOQk1IBX003PxJg&#39;;return true;">org.jenkinsci.plugins.workflow.job.WorkflowRun for Pipeline jobs
    • project == <a href="http://javadoc.jenkins-ci.org/hudson/model/Run.html#getParent%28%29" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fjavadoc.jenkins-ci.org%2Fhudson%2Fmodel%2FRun.html%23getParent%2528%2529\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGSrGOsm_hozySb8Csfn42X626ROQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fjavadoc.jenkins-ci.org%2Fhudson%2Fmodel%2FRun.html%23getParent%2528%2529\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGSrGOsm_hozySb8Csfn42X626ROQ&#39;;return true;">build.getParent() ... <a href="http://javadoc.jenkins.io/plugin/workflow-job/org/jenkinsci/plugins/workflow/job/WorkflowJob.html" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fjavadoc.jenkins.io%2Fplugin%2Fworkflow-job%2Forg%2Fjenkinsci%2Fplugins%2Fworkflow%2Fjob%2FWorkflowJob.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH9ekb2XUOzAo9WWsOtOkxiiYySYQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fjavadoc.jenkins.io%2Fplugin%2Fworkflow-job%2Forg%2Fjenkinsci%2Fplugins%2Fworkflow%2Fjob%2FWorkflowJob.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH9ekb2XUOzAo9WWsOtOkxiiYySYQ&#39;;return true;">org.jenkinsci.plugins.workflow.job.WorkflowJob - the job/project instance for this build
    • it ... <a href="https://github.com/jenkinsci/email-ext-plugin/blob/master/src/main/java/hudson/plugins/emailext/plugins/content/ScriptContentBuildWrapper.java" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkinsci%2Femail-ext-plugin%2Fblob%2Fmaster%2Fsrc%2Fmain%2Fjava%2Fhudson%2Fplugins%2Femailext%2Fplugins%2Fcontent%2FScriptContentBuildWrapper.java\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFUE4xC7tCwAi-PZo8MBrmDE6FWjw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkinsci%2Femail-ext-plugin%2Fblob%2Fmaster%2Fsrc%2Fmain%2Fjava%2Fhudson%2Fplugins%2Femailext%2Fplugins%2Fcontent%2FScriptContentBuildWrapper.java\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFUE4xC7tCwAi-PZo8MBrmDE6FWjw&#39;;return true;">ScriptContentBuildWrapper(build) (internal ExtEmail class)
    • rootUrl … Jenkins URL as set in your Jenkins configuration

 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

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/dfe5f429-b31f-4dac-af88-65c98f8806b6%40googlegroups.com.