ext-email and jelly template

204 views
Skip to first unread message

dpreilan

unread,
Oct 13, 2011, 5:17:58 PM10/13/11
to Jenkins Users
I don't have a good handle on what is or is not possible here.

I want to provide a custom email template for a job.

First thing I am stuck on is how to get upstream build info.

In this a case, a have a job that is trigger on completion of another
job.
For example, work-job triggers finish-job, and finish-job does the
email stuff.

I see in current templates printing stuff like date build, build url,
etc...
How can I can that information for the build that triggered finish-
job? Possible?

something like, build.upstreamBuild ??

Also, is there a way to include data in the email? For example, work-
job passes make.log to finish-job as an artifact. What is the best way
to include that in the email message?

Thanks!

Slide

unread,
Oct 13, 2011, 5:26:22 PM10/13/11
to jenkins...@googlegroups.com

Doing complex stuff in jelly is a pain in the butt in my opinion, which is why I implemented generating emails using groovy (and other scripting languages), I have done something similar to what you are trying to do using the groovy scripting. As for the other item, you can add attachments to the email using the attachments pattern in the project setup.

dpreilan

unread,
Oct 13, 2011, 5:31:04 PM10/13/11
to Jenkins Users
Thanks for reply.

How would this be done with groovy? Doing a post-task vs. using email
notification plugin?

Do you have any examples you can share?

On Oct 13, 5:26 pm, Slide <slide.o....@gmail.com> wrote:
> Doing complex stuff in jelly is a pain in the butt in my opinion, which is
> why I implemented generating emails using groovy (and other scripting
> languages), I have done something similar to what you are trying to do using
> the groovy scripting. As for the other item, you can add attachments to the
> email using the attachments pattern in the project setup.

Slide

unread,
Oct 13, 2011, 5:34:04 PM10/13/11
to jenkins...@googlegroups.com

Email-ext allows you to use a script already, so its all part of that. I need to update the wiki still on how to use it. I will do that tomorrow when I am back from the land of no computers.

Kamal Ahmed

unread,
Oct 13, 2011, 10:03:24 PM10/13/11
to jenkins...@googlegroups.com
I get this error:
+ cppncss -d -k -r -x src
Build step 'Execute shell' marked build as failure
ERROR: Publisher hudson.plugins.cppncss.CppNCSSPublisher aborted due to exception
hudson.util.IOException2: only whitespace content allowed before start tag and not / (position: START_DOCUMENT seen /... @1:1)
at hudson.plugins.helpers.BuildProxy.unwrapException(BuildProxy.java:104)
at hudson.plugins.helpers.BuildProxy.doPerform(BuildProxy.java:77)
at hudson.plugins.helpers.AbstractPublisherImpl.perform(AbstractPublisherImpl.java:30)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:19)
at hudson.model.AbstractBuild$AbstractRunner.perform(AbstractBuild.java:694)
at hudson.model.AbstractBuild$AbstractRunner.performAllBuildSteps(AbstractBuild.java:669)
at hudson.model.AbstractBuild$AbstractRunner.performAllBuildSteps(AbstractBuild.java:647)
at hudson.model.Build$RunnerImpl.post2(Build.java:162)
at hudson.model.AbstractBuild$AbstractRunner.post(AbstractBuild.java:616)
at hudson.model.Run.run(Run.java:1429)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:230)
Caused by: java.lang.Exception: hudson.util.IOException2: only whitespace content allowed before start tag and not / (position: START_DOCUMENT seen /... @1:1)
at hudson.plugins.helpers.BuildProxyCallableHelper.call(BuildProxyCallableHelper.java:54)
at hudson.plugins.helpers.BuildProxyCallableHelper.call(BuildProxyCallableHelper.java:15)
at hudson.FilePath.act(FilePath.java:813)
at hudson.plugins.helpers.BuildProxy.doPerform(BuildProxy.java:68)
... 11 more
Caused by: hudson.util.IOException2: only whitespace content allowed before start tag and not / (position: START_DOCUMENT seen /... @1:1)
at hudson.plugins.cppncss.parser.Statistic.parse(Statistic.java:152)
at hudson.plugins.cppncss.CppNCSSGhostwriter.performFromSlave(CppNCSSGhostwriter.java:79)
at hudson.plugins.helpers.BuildProxyCallableHelper.call(BuildProxyCallableHelper.java:51)
... 14 more
Caused by: org.xmlpull.v1.XmlPullParserException: only whitespace content allowed before start tag and not / (position: START_DOCUMENT seen /... @1:1)
at org.xmlpull.mxp1.MXParser.parseProlog(MXParser.java:1519)
at org.xmlpull.mxp1.MXParser.nextImpl(MXParser.java:1395)
at org.xmlpull.mxp1.MXParser.next(MXParser.java:1093)
at hudson.plugins.cppncss.parser.Statistic.expectNextTag(Statistic.java:194)
at hudson.plugins.cppncss.parser.Statistic.parse(Statistic.java:48)
... 16 more

Slide

unread,
Oct 14, 2011, 3:44:24 PM10/14/11
to jenkins...@googlegroups.com
This is how I do something similar:

<%
// the goal is to find the top level job which should contain the changelist
def upstreamBuild = null
def cause = build.causes.find {
if(it instanceof hudson.model.Cause.UpstreamCause) {
return true
}
return false
}

while(cause != null) {
upstreamBuild =
hudson.model.Hudson.instance.getItem(cause.upstreamProject).getBuildByNumber(cause.upstreamBuild)
cause = upstreamBuild.causes.find {
if(it instanceof hudson.model.Cause.UpstreamCause) {
return true
}
return false
}
}
%>
<!-- CHANGE SET -->
<%
if(upstreamBuild != null) {
// now do stuff with that upstream build
}
%>

...

--
slide-o-blog
http://slide-o-blog.blogspot.com/

dpreilan

unread,
Oct 16, 2011, 7:23:27 PM10/16/11
to Jenkins Users
Slide,

Who do I use this? Do I make a new groovy script and invoke with the $
{SCRIPT,...} in the Default Content? Sorry, if this a stupid question
because I don't understand how this is put together yet.

Note, as I test. I copy the email-ext.goovy and the groovy-
html.template over to ${JENKINS_HOME}/email-templates, renamed them,
and try the ${SCRIPT,"new.groovy","new.template",true} and resulting
email just echoes the line. The token doesn't get processed.

Doug

Slide

unread,
Oct 16, 2011, 7:35:35 PM10/16/11
to jenkins...@googlegroups.com

You need to fill in the argument names as well ${SCRIPT, template="template.template"}

If you don't need any different script, you can just supply a template that will automatically get processed with the default groovy script. The template can include groovy script code which is where you would put something like I provided.

I'm working on the wiki.

dpreilan

unread,
Oct 16, 2011, 8:51:07 PM10/16/11
to Jenkins Users
Ok, that worked! It starting to make sense.
Thanks again for your time and the plugin.

On Oct 16, 7:35 pm, Slide <slide.o....@gmail.com> wrote:
> You need to fill in the argument names as well ${SCRIPT,
> template="template.template"}
>
> If you don't need any different script, you can just supply a template that
> will automatically get processed with the default groovy script. The
> template can include groovy script code which is where you would put
> something like I provided.
>
> I'm working on the wiki.
Reply all
Reply to author
Forward
0 new messages