Get previous build result

No need to access rawBuild, instead you can do the following without any special permissions:

currentBuild.getPreviousBuild().result

This will allow you to see the result of the previous build without needing to have any special privileges set by the Jenkins administrator. It should be able to be run anywhere.

Global Variable Reference: https://www.jenkins.io/doc/book/pipeline/getting-started/#global-variable-reference

And more specifically, in your own Jenkins: ${YOUR_JENKINS_URL}/pipeline-syntax/globals#currentBuild

More information: https://support.cloudbees.com/hc/en-us/articles/217591038-How-to-Iterate-Through-the-Last-Successful-Builds-in-Pipeline-Job


If you approve the method getRawBuild from Manage Jenkins > In-process Script Approval after you get RejectedAccessException on a build, you can use the method from a next build even in the groovy sandbox.

Besides getRawBuild, you need to approve getPreviousBuild and getResult one by one after you get the exception against each method for your script.