1

I have groovy email template(for Selenium Robot framework test execution) for Jenkins. Jenkins master is controlled by a remote team. So for placing this template in $JENKINS_HOME/email-templates, we need to raise a ticket and wait from 2 to 3 days. Also we expect, there might be changes required in template. So we are planning to put our templates inside our source code repository (GIT). so in the Jenkins test job, we checkout the test script together with email templates. How to instruct Jenkins to look for the template in workspace folder instead of $JENKINS_HOME/email-templates in Jenkins Master

  • I'm working on adding this feature to email-ext. Basically it will allow you to specify a workspace relative path in the content tokens. For example, if you had a template at WORKSPACE/templates/foo.template, you would specify ${SCRIPT, template="templates/foo.template"} to use that template. – slide Apr 19 '16 at 23:48
  • @slide Thanks a lot. It would be really helpful – Jagadish Chandran Apr 21 '16 at 05:18
  • @slid, any update on your work of the template path? – Heinz Aug 24 '17 at 17:23
  • I handed off development of the plugin to someone else because I didn't have time to continue working on it. I know there was some push back on this because of security considerations. – slide Aug 25 '17 at 18:14

2 Answers2

1

Sadly it seems you would need to modify the email-ext plugin as the search path is hardcoded into it.

You can see it here, check the occurrence on line 69 in file src/main/java/hudson/plugins/emailext/EmailExtTemplateAction.java

Changing it to another path would be trivial, however adding multiple locations you'd probably have to put some work in.

Edit: I wonder if it would be possible to put the wanted stuff into some txt file as a build step, and then load it into the mail content via some template configuration. If you have access to the job configuration this might be worth checking.

Dominik Gebhart
  • 2,980
  • 1
  • 16
  • 28
  • If I have the wanted stuff in some text file, How can I load it in to mail content... Can you provide me some info on template configuration – Jagadish Chandran Mar 31 '16 at 08:03
  • Try `${FILE,path="sometext.txt"}`, you can find the *content token reference* in jenkins email template configuration, right under the *attach build log* settings. – Dominik Gebhart Mar 31 '16 at 09:05
0

You can copy the template into the build workspace (e.g. with SCM step), and then email-ext can reach it:

${SCRIPT, template="${WORKSPACE}/foo.template"}
Noam Manos
  • 15,216
  • 3
  • 86
  • 85
  • I tried that, but got the error message: `Groovy Template file [$WORKSPACE/foo.template] was not found in $JENKINS_HOME/email-templates.` That `$WORKSPACE`-Variable is working at other places in the Jenkinsfile. Plugin-Version: 2.80 – nasezoll Dec 07 '21 at 09:09
  • I'm still using this method with latest Jenkins version, and even when the UI alerts on missing template, I can save the configuration. Once the build run and finished, an email is being sent using this template path under workspace, if the file is in the workspace. – Noam Manos Dec 08 '21 at 21:07