Issue
I want to be able to check on the status of my previous build in a pipeline script.
Environment
- CloudBees CI (CloudBees Core) on modern cloud platforms - Managed Master
- CloudBees CI (CloudBees Core) on traditional platforms - Client Master
- CloudBees Jenkins Enterprise - Managed Master
- CloudBees Jenkins Platform - Client Master
- CloudBees Jenkins Distribution
- Jenkins LTS
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 whitelisted:
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.
0 Comments