Resolution
This would be what your pipeline script would look like:
if(!hudson.model.Result.SUCCESS.equals(currentBuild.rawBuild.getPreviousBuild()?.getResult())) { echo "last build failed" }
This will check if the last build was a failure and then echo that the last build failed.
Several methods will need to be allowlisted:
-
method hudson.model.Run getPreviousBuild
-
method hudson.model.Run getResult
-
method org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper getRawBuild
Tested product/plugin versions
This was last tested on Jenkins 2.204.1 with the Script Security Plugin version 1.68.