Skip to content

Instantly share code, notes, and snippets.

@slide
Created April 30, 2018 19:57
Show Gist options
  • Save slide/b7336e5d671b87be80831a086a8f9da5 to your computer and use it in GitHub Desktop.
Save slide/b7336e5d671b87be80831a086a8f9da5 to your computer and use it in GitHub Desktop.
@NonCPS
def getLastJobInfo(build) {
def res = null
try {
if(build.previousBuild != null) {
def resp = httpRequest(quiet: true, url: "http://SERVER/jenkins/job/SOMEJOB/job/Pipeline/${build.previousBuild.id}/wfapi/describe")
res = readJSON(text: resp.content)
}
} catch(e) {
res = null
}
return res
}
...
try {
lastJob = getLastJobInfo(currentBuild.rawBuild)
if(lastJob != null) {
def s = lastJob.stages.find { st -> st.name.compareToIgnoreCase(stageName) == 0 && st.status != 'SUCCESS' }
if(s != null) {
// do something here!
}
}
} catch(e) {
// some error
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment