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

Issue

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

Environment

  • CloudBees Jenkins Enterprise

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.

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

0 Comments

Please sign in to leave a comment.