Created
October 25, 2018 21:07
-
-
Save jeffnelson/c5e687ff046d6a1f1c31039db3bcc907 to your computer and use it in GitHub Desktop.
jenkins groovy script to get the build result of a given build's upstream cause
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
import jenkins.model.Jenkins | |
import hudson.model.AbstractItem | |
import hudson.model.Cause | |
// === this code enables you to run this whole thing === | |
// === just in https://myjenkins.me/script console === | |
def currentBuild = Jenkins.instance.getAllItems(AbstractItem.class) | |
.findAll{ it.fullName == "my/org/job-name" } | |
.collect{ it.builds.findAll{ it.number == 3 } } // desired build number of "my/org/job-name" | |
.flatten()[0] | |
// ===================================================== | |
// the below code can be used in a groovy script in a jenkins job because 'currentBuild' is available in context | |
Cause.UpstreamCause cause = currentBuild.getCause(Cause.UpstreamCause.class) | |
def upstreamTriggerBuildResult = Jenkins.instance.getAllItems(AbstractItem.class) | |
.findAll{ it.fullName == cause.getUpstreamProject() } | |
.collect{ proj -> proj.getBuilds().findAll{ it.number == cause.getUpstreamBuild() }.collect{ it.getResult() } } | |
.flatten()[0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment