how to determine current build status (SUCCESS, FAIL) within a custom build step script

I'd like to have a script like this:

if [[ %build.status% == "SUCCESS" ]]

but I see no way to retrieve the current build status from within a build step. Is there a way to accomplish this? Alternatively is there a way to set the step execution policy to "Only if previous step was NOT successful"?

Please sign in to leave a comment.