Environment
-
CloudBees CI (CloudBees Core) on modern cloud platforms - Managed controller
-
CloudBees CI (CloudBees Core) on traditional platforms - Client controller
-
CloudBees Jenkins Enterprise - Managed controller
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.
This article is part of our Knowledge Base and is provided for guidance-based purposes only. The solutions or workarounds described here are not officially supported by CloudBees and may not be applicable in all environments. Use at your own discretion, and test changes in a safe environment before applying them to production systems.