[JIRA] [email-ext-plugin] (JENKINS-26478) Store Content Token Email Body In A File So It Can Be Reused In Other Jobs

91 views
Skip to first unread message

timmy.leahy@gmail.com (JIRA)

unread,
Jan 16, 2015, 6:18:51 PM1/16/15
to jenkinsc...@googlegroups.com
Issue Type: Improvement Improvement
Assignee: Alex Earl
Components: email-ext-plugin
Created: 16/Jan/15 11:18 PM
Description:

I've been trying to setup a few jobs with the email-ext plugin to get a more detailed email report for each build. The email-ext plugin is currently configured to have all of the Content Token content in the Default Content field. The content is the same in all of them and I would like to store the template in a file and reference that file in the jobs.

I havent' been able to determine if this is possible based on the documentation or from related questions on stackoverflow and other sites.

It seems like the only way to use a file based template is to use the {SCRIPT} or {JELLY_SCRIPT} tags pointing to a file in $JENKINS_HOME/email-templates or the Config File Plugin with the "managed:" prefix. When using either of those tags with a simple Content Token formatted template I get multiple parsing errors (unexpected token) trying to evaluate them as either Groovy or Jelly. This same content parses just fine when used in the Default Content field.

I don't have any need for Jelly or Groovy at this point, I just want to reuse the same Content Token formatted template in multiple jobs.

Is what I'm trying to do possible? If it is, could the documentation be updated to refelct how to store, format, and refernece that kind of template in a job?

Project: Jenkins
Priority: Minor Minor
Reporter: Timmy Leahy
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators.
For more information on JIRA, see: http://www.atlassian.com/software/jira

slide.o.mix@gmail.com (JIRA)

unread,
Jan 16, 2015, 6:34:56 PM1/16/15
to jenkinsc...@googlegroups.com
Alex Earl commented on Improvement JENKINS-26478

Can you give information on the parsing errors you are getting and attach the files you are using? The template mechanism uses Groovy or Jelly, those are the options, there is no other way to use a file.

timmy.leahy@gmail.com (JIRA)

unread,
Jan 16, 2015, 6:46:52 PM1/16/15
to jenkinsc...@googlegroups.com
Timmy Leahy commented on Improvement JENKINS-26478

Hi Alex. Thanks for the reply.

The template (right now) it pretty simple but I wanted to make it into a file and a little more elaborate. That's when I ran into not being able to just use the Content Token format.

${DEFAULT_CONTENT}

${FILE, path="report.html"}

<h1>Changes</h1>
${CHANGES}

(the html file is just some output from a reporting tool that I need included inline in the email)

And here were the errors when using the {SCRIPT, template=...} and {SCRIPT, script=...}

Error in script or template: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script1.groovy: 3: unexpected token: FILE @ line 3, column 3. ${FILE, path="jenkins/buildstate.html"} ^ 1 error

Exception raised during template rendering: Failed to parse template script (your template may contain an error or be trying to use expressions not currently supported): startup failed: SimpleTemplateScript3.groovy: 3: unexpected token: FILE @ line 3, column 3. ${FILE, path="jenkins/buildstate.html"} ^ 1 error

I would prefer to use the Content Token format because it would be easier for non Groovy/Jelly people to maintain. But it sounds like from what you just said that the template files must be either Jelly or Groovy.

slide.o.mix@gmail.com (JIRA)

unread,
Jan 16, 2015, 6:50:52 PM1/16/15
to jenkinsc...@googlegroups.com
Alex Earl commented on Improvement JENKINS-26478

You can use similar things like the content tokens inside the groovy templates. Try this (untested)

${DEFAULT_CONTENT()}

${FILE(path: 'report.html')}
<h1>Changes</h1>
${CHANGES()}

timmy.leahy@gmail.com (JIRA)

unread,
Jan 16, 2015, 6:50:51 PM1/16/15
to jenkinsc...@googlegroups.com
 
Timmy Leahy edited a comment on Improvement JENKINS-26478

Hi Alex. Thanks for the reply.

The template (right now) it pretty simple but I wanted to make it into a file and a little more elaborate. That's when I ran into not being able to just use the Content Token format.

${DEFAULT_CONTENT}

${FILE, path="report.html"}

<h1>Changes</h1>
${CHANGES}

(the html file is just some output from a reporting tool that I need included inline in the email)

And here were the errors when using the {SCRIPT, template=...} and {SCRIPT, script=...}

Error in script or template: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script1.groovy: 3: unexpected token: FILE @ line 3, column 3. ${FILE, path="report.html"} ^ 1 error

Exception raised during template rendering: Failed to parse template script (your template may contain an error or be trying to use expressions not currently supported): startup failed: SimpleTemplateScript3.groovy: 3: unexpected token: FILE @ line 3, column 3. ${FILE, path="report.html"} ^ 1 error

I would prefer to use the Content Token format because it would be easier for non Groovy/Jelly people to maintain. But it sounds like from what you just said that the template files must be either Jelly or Groovy.

This message is automatically generated by JIRA.

timmy.leahy@gmail.com (JIRA)

unread,
Jan 16, 2015, 7:07:52 PM1/16/15
to jenkinsc...@googlegroups.com
Timmy Leahy commented on Improvement JENKINS-26478

Yeah, that works in the template file. The Content Token to Groovy syntax mapping seems pretty straight forward so I'll just switch to groovy.

But perhaps making a note of this in the https://wiki.jenkins-ci.org/display/JENKINS/Email-ext+plugin or in the "?" help pop-in for "Default Content" and "Content Token Reference" might help someone in the future if they run into this.

timmy.leahy@gmail.com (JIRA)

unread,
Jan 16, 2015, 7:26:51 PM1/16/15
to jenkinsc...@googlegroups.com
Timmy Leahy commented on Improvement JENKINS-26478

Acutally that doesn't work 100%

[Could not find content token (check your usage): DEFAULT_CONTENT]

But FILE() and CHANGES() work.

slide.o.mix@gmail.com (JIRA)

unread,
Jan 16, 2015, 10:55:52 PM1/16/15
to jenkinsc...@googlegroups.com
Alex Earl commented on Improvement JENKINS-26478

Hmmm, I'll have to look at why DEFAULT_CONTENT doesn't work.

slide.o.mix@gmail.com (JIRA)

unread,
Jan 29, 2015, 8:35:52 PM1/29/15
to jenkinsc...@googlegroups.com
Alex Earl commented on Improvement JENKINS-26478

Looks like only non-private tokens are currently supported this way. The DEFAULT_CONTENT token is a "private" token to email-ext, so it's not exposed to the token-macro interface directly.

slide.o.mix@gmail.com (JIRA)

unread,
Jan 31, 2015, 11:55:52 PM1/31/15
to jenkinsc...@googlegroups.com
Alex Earl commented on Improvement JENKINS-26478

The other thing you could do is something like this in the content entry field:

$DEFAULT_CONTENT

${SCRIPT, template="groovyFileThatDoesAllTheContentTokenStuff.template"}

scm_issue_link@java.net (JIRA)

unread,
Feb 22, 2015, 7:45:31 AM2/22/15
to jenkinsc...@googlegroups.com

Code changed in jenkins
User: Alex Earl
Path:
src/main/java/hudson/plugins/emailext/AttachmentUtils.java
src/main/java/hudson/plugins/emailext/plugins/ContentBuilder.java
src/main/java/hudson/plugins/emailext/plugins/content/AbstractEvalContent.java
src/main/java/hudson/plugins/emailext/plugins/content/JellyScriptContent.java
src/main/java/hudson/plugins/emailext/plugins/content/ScriptContent.java
src/main/java/hudson/plugins/emailext/plugins/content/TemplateContent.java
src/main/resources/hudson/plugins/emailext/plugins/content/TemplateContent/help.groovy
src/test/java/hudson/plugins/emailext/plugins/content/JellyScriptContentTest.java
src/test/java/hudson/plugins/emailext/plugins/content/ScriptContentTest.java
http://jenkins-ci.org/commit/email-ext-plugin/9b00d7831e6097de30ebbc9366ff4d6d836513f8
Log:
Fix JENKINS-26478

Added new TEMPLATE content token that can be used to pull in email
content from a file.

slide.o.mix@gmail.com (JIRA)

unread,
Feb 22, 2015, 7:48:32 AM2/22/15
to jenkinsc...@googlegroups.com
Alex Earl resolved Improvement JENKINS-26478 as Fixed

Added new TEMPLATE token that will take content from a txt file, or managed file.

Change By: Alex Earl (22/Feb/15 12:47 PM)
Status: Open Resolved
Resolution: Fixed

timmy.leahy@gmail.com (JIRA)

unread,
Feb 24, 2015, 7:19:31 PM2/24/15
to jenkinsc...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages