Skip to content

Instantly share code, notes, and snippets.

@pditommaso
Created November 15, 2011 17:31
Show Gist options
  • Save pditommaso/1367710 to your computer and use it in GitHub Desktop.
Save pditommaso/1367710 to your computer and use it in GitHub Desktop.
/*
* This is script for the Jenkins email-ext plugin.
* It make it possibile to send a mail for failing downstream jobs to
* source committer. It have to be used for.
*
* Usage: save this script in $JENKINS_HOME/email-templates/committers.groovy
* In the job configuration use the value "${SCRIPT, script="committers.groovy"}"
* in the field "Global Recipient List" for the component "Editable Email Notification"
*
*/
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) {
def email = cs.user.contains("@") ? cs.user : cs.user + "@gmail.com"
committers.add(email)
}
}
}
committers.unique().join(',')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment