Pipeline - How can I check previous build status in a Pipeline Script?


  • I want to be able to check on the status of my previous build in a pipeline script


  • Jenkins
  • CloudBees Jenkins Enterprise
  • Pipeline plugin


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.

WARNING: Groovy sandbox has to be disabled for this to work because it is accessing the filesystem. RawBuild will also have to be whitelisted by the script security plugin once the Groovy sandbox is disabled.


Have more questions? Submit a request


Please sign in to leave a comment.