Skip to content

Instantly share code, notes, and snippets.

@MachinesAreUs
Forked from chrix2/gist:2232656
Created June 29, 2012 00:45
Show Gist options
  • Save MachinesAreUs/3014977 to your computer and use it in GitHub Desktop.
Save MachinesAreUs/3014977 to your computer and use it in GitHub Desktop.
Get parent build Jenkins
def myJob = hudson.model.Hudson.instance.getItem("My_Job")
def lastBuild = myJob.getLastBuild()
def cause = lastBuild.getCause(hudson.model.Cause$UpstreamCause)
def parentBuildNum = cause.upstreamBuild
def parentJobName = cause.upstreamProject
def parentJobUrl = cause.upstreamUrl
println(parentBuildNum)
println(parentJobName)
println(parentJobUrl)
def parentJob = hudson.model.Hudson.instance.getItem(parentJobName)
def parentBuild = parentJob.getBuildByNumber(parentBuildNum)
println(parentBuild.getNumber())
println(parentBuild.getId())
println(parentBuild.getUrl())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment