Get the status of a particular stage in a previous build, in a Jenkinsfile

38 views
Skip to first unread message

Adam Bowen

unread,
Mar 26, 2019, 10:13:59 PM3/26/19
to Jenkins Users
Is there a way to get the status of a stage for a previous build inside of a Jenkinsfile (i.e. Groovy). My situation is that I have a lengthy multistage pipeline. A lot of the stages have conditionals that cause the stage only to run if  a file has been changed since the last successful build. Sometimes that stage may be successful in the last build, but perhaps the overall build failed due to another stage. I want to be able to query what stages were successful in a failed build. I can;t seem to find any syntax that supports that, 

Slide

unread,
Mar 27, 2019, 8:45:37 AM3/27/19
to Jenkins User Mailing List
I have done this using the following code, but was told that this may not work in future versions:

@NonCPS
def getLastJobInfo(build) {
  def res = null
  try {
    if(build.previousBuild != null) {
      def resp = httpRequest(quiet: true, url: "${env.BUILD_URL}/${build.previousBuild.id}/wfapi/describe")
      res = readJSON(text: resp.content)
    }
  } catch(e) {
    res = null
  }
  return res
}


On Tue, Mar 26, 2019 at 7:13 PM Adam Bowen <pop...@gmail.com> wrote:
Is there a way to get the status of a stage for a previous build inside of a Jenkinsfile (i.e. Groovy). My situation is that I have a lengthy multistage pipeline. A lot of the stages have conditionals that cause the stage only to run if  a file has been changed since the last successful build. Sometimes that stage may be successful in the last build, but perhaps the overall build failed due to another stage. I want to be able to query what stages were successful in a failed build. I can;t seem to find any syntax that supports that, 

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/cc3333c0-ebe1-4f38-afb4-227dd06814de%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Reply all
Reply to author
Forward
0 new messages