How notify committers when a downstream job fail.

190 views
Skip to first unread message

Paolo Di Tommaso

unread,
Nov 4, 2011, 8:01:35 AM11/4/11
to jenkins...@googlegroups.com
Dear all, 

I've have a build job that downloads the code form the repository and compiles it. 

When it terminates successfully it triggers a downstream job that tests the compiled artifacts. 

If some test fail I would like to notify the committer of the latests changes that something is went wrong (as it happens if the build job fail). 

Is there a way to do that? I was unable to make it work in a such way.


Thanks for any suggestions. 
Paolo

Slide

unread,
Nov 4, 2011, 9:10:50 AM11/4/11
to jenkins...@googlegroups.com
The official answer to this I believe is to have some sort of
dependency between the two jobs (an artifact, etc), but I never got
that to work correctly. So, I use the groovy scripting capabilities of
email-ext to walk the hierarchy of projects until I get to the top
level one that started my job and has the SCM information, and I grab
the commiters info from there and append to my email list (the
recipients list can have SCRIPT token in it just like the subject and
content areas can). This seems to work well for me.

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

Paolo Di Tommaso

unread,
Nov 4, 2011, 10:27:51 AM11/4/11
to jenkins...@googlegroups.com
Quite interesting, you would share an example to do that? 

Thanks,
Paolo

Ferenc Kovacs

unread,
Nov 4, 2011, 10:36:13 AM11/4/11
to jenkins...@googlegroups.com
I would be also interested in your groovy script.
--
Ferenc Kovács
@Tyr43l - http://tyrael.hu

Slide

unread,
Nov 4, 2011, 11:56:10 AM11/4/11
to jenkins...@googlegroups.com
In the "Global Recipient List" in the project setup I have the following:

${SCRIPT, script="committers.groovy"}

committers.groovy has the following content.

/*************************************************************************************************/

// 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
}

try {
while(cause != null) {
upstreamBuild =
hudson.model.Hudson.instance.getItem(cause.upstreamProject).getBuildByNumber(cause.upstreamBuild)
if(upstreamBuild == null) {
break;
}
cause = upstreamBuild.causes.find {
if(it instanceof hudson.model.Cause.UpstreamCause) {
return true
}
return false
}
}
} catch(e) {
// do nothing
}

// now we loop through the changeset and add all the users to a list
committers = []

if(upstreamBuild != null && upstreamBuild.changeSet != null) {
upstreamBuild.changeSet.each() { cs ->
if(cs.user != null) {
committers.add(cs.user)
}
}
}

committers.unique().join(',')

/************************************************************************************************************/

The last line must evaluate to a string. This requires email-ext 2.15,
but there is a known issue in there with a feature I added, so you may
want to try grabbing the latest github source and compile you own
version (I'm working on getting a release out).

Thanks,

slide


On Fri, Nov 4, 2011 at 7:27 AM, Paolo Di Tommaso

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

Dirk Kuypers

unread,
Nov 4, 2011, 12:10:08 PM11/4/11
to jenkins...@googlegroups.com
You need to fingerprint a file common to your upstream and downstream
job to get a strong relation between your jobs. I am using a DLL to
achieve this for a continuous compile job and more than 20 unit tests
projects which are started by the compile job. Both, the up- and
downstream job have to fingerprint the same file.

After doing that you are able to access the changes from the upstream
job via email-ext plugin in the downstream job, f.i:
${CHANGES_SINCE_LAST_SUCCESS, showPaths=true, pathformat="%p"}

HTH
Dirk
2011/11/4 Ferenc Kovacs <tyr...@gmail.com>:

--
Never trust a short-haired guru

Bap

unread,
Nov 4, 2011, 12:44:26 PM11/4/11
to jenkins...@googlegroups.com

Quoting Slide <slide...@gmail.com>:

> In the "Global Recipient List" in the project setup I have the following:
>
> ${SCRIPT, script="committers.groovy"}
>
> committers.groovy has the following content.
>
> /*************************************************************************************************/
>
> // 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
> }

The above can be simplified to:

def cause = build.causes.find { it instanceof
hudson.model.Cause.UpstreamCause }

Bap.

Slide

unread,
Nov 4, 2011, 1:41:02 PM11/4/11
to jenkins...@googlegroups.com
Cool, I am by no means an expert with groovy, so it's good to find out
ways to optimize.

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

Paolo Di Tommaso

unread,
Nov 14, 2011, 7:04:41 PM11/14/11
to jenkins...@googlegroups.com
Dear all, 

Thanks for sharing the script. It works, but it turns out that the committers does not include the host domain name in the  email addresses retrieved by the script, so the email send is failing . 

Email was triggered for: Failure
Sending email for trigger: Failure
Sending email to: paolo.ditommaso
ERROR: Could not send email as a part of the post-build publishers.
javax.mail.SendFailedException: Invalid Addresses;

 
I think this is due to the fact that the Google SVN repository, that I'm using, does not include the email host domain name in the committer info, but for this reason the Jenkins email component had a "Default user e-mail suffix" field where it is possibile to specify host name when it is missing. 

Is this possible with the mail-ext pluging is some way? or is there any other workaround ? 


Thank for your help . 


Cheers,

Slide

unread,
Nov 14, 2011, 7:23:02 PM11/14/11
to jenkins...@googlegroups.com

That setting should still work.

Paolo Di Tommaso

unread,
Nov 15, 2011, 4:55:43 AM11/15/11
to jenkins...@googlegroups.com
But it does not. 

Paolo

Slide

unread,
Nov 15, 2011, 8:03:31 AM11/15/11
to jenkins...@googlegroups.com
Can you file a ticket in JIRA for this? It shouldn't be too hard to add. In the groovy script you are using, you could add the @foo.com suffix to everything as a temporary solution.

slide

Paolo Di Tommaso

unread,
Nov 15, 2011, 8:20:50 AM11/15/11
to jenkins...@googlegroups.com
OK. Send me please the URL to the JIRA tracking system 

Thanks, 
Paolo

Slide

unread,
Nov 15, 2011, 8:49:22 AM11/15/11
to jenkins...@googlegroups.com

Paolo Di Tommaso

unread,
Nov 15, 2011, 11:03:34 AM11/15/11
to jenkins...@googlegroups.com
Here it is  https://issues.jenkins-ci.org/browse/JENKINS-11731

Thank you,
Paolo


On Tue, Nov 15, 2011 at 2:49 PM, Slide <slide...@gmail.com> wrote:
https://issues.jenkins-ci.org.


Reply all
Reply to author
Forward
0 new messages