-
-
Save lifuzu/046d52025922bdccc6dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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