I have a pipeline with different stages. I want the current job to check how many stages have passed in the previous build and log it in the console?
Consider this is my current pipeline
node(){
stage "1"
do something
stage "2"
do something else
}
I want a groovy script to give my something like this
println currentBuild.previousBuild.getStage("1").result
The purpose of my code is track successes & failures in different stages across my builds. Are there any alternatives to this approach?
You definitely could use Pipeline REST API Plugin, for me it was available out of the box with Jenkins 2.13.
By parsing the resulting JSON you could get the status of the stage similarly to what you expect. For the api call I personally use http_request plugin.
From the documentation GET /job/:job-name/:run-id/wfapi/describe returns:
Here is a sample code to iterate all flow nodes and get whatever information you want:
You can iterate all stages of the build and do what you need: