Skip to content

Instantly share code, notes, and snippets.

@chrix2
Created March 29, 2012 02:34
Show Gist options
  • Save chrix2/2232656 to your computer and use it in GitHub Desktop.
Save chrix2/2232656 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())
@MachinesAreUs
Copy link

Useful for a build/deployment pipeline!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment