Resolution
This can be accomplished using the currentBuild
and use the getPreviousBuild()
linkage recursively. The following retrieves all the passed build since the lastSuccessfulBuild chronologically and add them to an array.
passedBuilds = [] def lastSuccessfullBuild(build) { if(build != null && build.result != 'FAILURE') { //Recurse now to handle in chronological order lastSuccessfullBuild(build.getPreviousBuild()); //Add the build to the array passedBuilds.add(build); } } lastSuccessfullBuild(currentBuild.getPreviousBuild());