email-ext - jelly script example for matrix job

1,106 views
Skip to first unread message

dpreilan

unread,
Mar 13, 2012, 11:25:20 AM3/13/12
to Jenkins Users
I want to extend my email-ext template to report more meaningful
reports for some matrix jobs

In addition, I want to change so instead of a bunch of separate emails
(12 in my case) for each matrix, 1 email from 'parent' job that
contains status and information for the individual matrix runs.

Anybody have example of how my template can do this?

Thanks,
Doug

Slide

unread,
Mar 13, 2012, 2:04:10 PM3/13/12
to jenkins...@googlegroups.com

There is already an issue filed for something like this, I don't believe its currently doable.

dpreilan

unread,
Mar 15, 2012, 5:51:38 PM3/15/12
to Jenkins Users
I decided to code this as a groovy script and invoke in the content
section. For example:
${SCRIPT,template="my-matrix-build-msg.template"}

Slide, I looked back on some information you gave me last year. Thanks
again!
I just had to work my way thru understanding jenkins objects.

Doug


On Mar 13, 2:04 pm, Slide <slide.o....@gmail.com> wrote:
> There is already an issue filed for something like this, I don't believe
> its currently doable.

Slide

unread,
Mar 15, 2012, 6:07:08 PM3/15/12
to jenkins...@googlegroups.com

Can you post your template for posterity?

dpreilan

unread,
Mar 19, 2012, 10:25:07 AM3/19/12
to Jenkins Users
Sure. I am not really a java or groovy coder so I am sure there are
ways to improve this code.
To explain, the job and email. I have matrix jobs that build for
various 'toolchains' and architectures (ia32, x86_64, and ia64). I
created generic axis names (AXIS1, and AXIS2) because of some unique
name collisions with our build environment so that may look weird.

I am only sending email on parent job now. This template will find
current runs for that parent, and print some summary status. I copied
the style stuff from the html-with-health-and-console jelly script
floating around.

I see there is no way to attach a file so I put my template in github
here:
g...@github.com:dpreilan/jenkins-ci-stuff.git

If you don't have access to git, I will email or cut&paste here.

Doug


On Mar 15, 6:07 pm, Slide <slide.o....@gmail.com> wrote:
> Can you post your template for posterity?

Slide

unread,
Mar 19, 2012, 11:26:38 AM3/19/12
to jenkins...@googlegroups.com
This is awesome. Thanks for sharing! I've heard of several people who would like to do something like this. I'll try and add it to the wiki for email-ext.

slide

dpreilan

unread,
Mar 19, 2012, 11:42:41 AM3/19/12
to Jenkins Users
Glad I could give back. Thanks for the plugin.

Chris Withers

unread,
Mar 23, 2012, 6:35:30 AM3/23/12
to jenkins...@googlegroups.com, Slide
On 19/03/2012 15:26, Slide wrote:
> This is awesome. Thanks for sharing! I've heard of several people who
> would like to do something like this. I'll try and add it to the wiki
> for email-ext.

Sorry for topic hijacking, but I tried asking this before and got no
response, yet this topic seems similar...

So, I have a job (A) that uses artifacts from another job (B) and is
also triggered by that job. That other job does the SCM polling, so when
tests in Job A fail, them changelog is blank, just says "triggered by
build #x of Job A".

Does anyone have an email-ext example of how to get the changelog from
Job A into the email-ext mail sent if Job B fails?

cheers,

Chris

--
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk

Slide

unread,
Mar 23, 2012, 8:48:19 PM3/23/12
to Chris Withers, jenkins...@googlegroups.com
I use something like this in my groovy template

// 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 {
        return (it instanceof hudson.model.Cause.UpstreamCause);
    }
}

Then I check if upstreamBuild is null or not, and if its not, I have access to its information like this:

def changeSet = upstreamBuild.changeSet

And you can get the info you are looking for from there.

slide

Chris Withers

unread,
Mar 24, 2012, 6:08:00 AM3/24/12
to Slide, jenkins...@googlegroups.com
On 24/03/2012 00:48, Slide wrote:
> I use something like this in my groovy template
>
> // 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 {
> return (it instanceof hudson.model.Cause.UpstreamCause);
> }
> }
>
> Then I check if upstreamBuild is null or not, and if its not, I have
> access to its information like this:
>
> def changeSet = upstreamBuild.changeSet
>
> And you can get the info you are looking for from there.

Wow, cool, I'm afraid I'm a bit clueless though...

Where do I put the code you've written above? File on disk or box in UI?
(it either case, where and called what?)

Once I've done that, how do I wire it into the email-ext template?

dpreilan

unread,
Mar 27, 2012, 4:48:53 PM3/27/12
to Jenkins Users
Create your groovy script and place in under your $JENKINS_HOME/email-
templates. Create the email-templates directory if needed.
Say you call it foo.template.

In your jenkins job(s), configure your "Editable Email Notification"
Content area, like:

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

Make sure you set 'Content Type' correctly (hml or text) based on what
output you are giving.
Also, if you have configured seperate triggers under advanced for
failured, fixed, ..., you might need to added the content there as
well which is what I do.

Doug

On Mar 24, 6:08 am, Chris Withers <ch...@simplistix.co.uk> wrote:
> On 24/03/2012 00:48, Slide wrote:
>
>
>
>
>
> > I use something like this in my groovy template
>
> > // 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).getBuildByNumbe­r(cause.upstreamBuild)
> >      cause = upstreamBuild.causes.find {
> >          return (it instanceof hudson.model.Cause.UpstreamCause);
> >      }
> > }
>
> > Then I check if upstreamBuild is null or not, and if its not, I have
> > access to its information like this:
>
> > def changeSet = upstreamBuild.changeSet
>
> > And you can get the info you are looking for from there.
>
> Wow, cool, I'm afraid I'm a bit clueless though...
>
> Where do I put the code you've written above? File on disk or box in UI?
> (it either case, where and called what?)
>
> Once I've done that, how do I wire it into the email-ext template?
>
> cheers,
>
> Chris
>
> --
> Simplistix - Content Management, Batch Processing & Python Consulting
>             -http://www.simplistix.co.uk- Hide quoted text -
>
> - Show quoted text -

Slide

unread,
Mar 27, 2012, 5:03:44 PM3/27/12
to jenkins...@googlegroups.com
You can use the PROJECT_DEFAULT_CONTENT in the triggers for them to use the same content as you specified in the main area for the content.
--
Website: http://earl-of-code.com

Kushal Gangan

unread,
Apr 3, 2015, 5:41:34 AM4/3/15
to jenkins...@googlegroups.com
Hi Doug,

Could you please paste that template over here ? As i am not able to get it from the git repo shared by you.

Thanks,
Kushal Gangan

sec...@in.tum.de

unread,
May 23, 2017, 9:44:02 AM5/23/17
to Jenkins Users
Hi,
I've attached a file, that is somewhat similar to the file in the wiki (https://wiki.jenkins-ci.org/display/JENKINS/Email-ext+plugin#Email-extplugin-TemplateExamples).
Difference is, that it gets the axes from the job automatically and works with an arbitrary number of axes.

Best,
Steffen
jenkins-generic-matrix-email-html.template
Reply all
Reply to author
Forward
0 new messages