stop a build with error status


I have a listener waiting for the buildStarted event so that I can perform a pre-requisite check before the build is run. If the check fails, I want the build to fail with an error message. When I use SRunningBuild.stop() it stops the build and shows the error message, which is almost perfect. However, the build status shows up as cancelled in the build history, and you can only see this if you have the "include canceled builds" option selected. If a user doesn't have it selected, it looks like the build was never run, which is confusing.

Alternatively, I have tried using SRunningBuild.setBuildStatus(Status.ERROR) which fails the build so it shows up in the history properly, but I don't have the option of providing a message as to why it failed. Also, even after I issue the command it continues to run the build until it is finished.

What I want is the functionality of calling stop(), but to have the build status show as failure instead of cancelled. Is this possible?




Hello Steve,

I think you can use
runningBuild.addBuildMessage(DefaultMessagesInfo.createBuildFailure("Failure reason"))

to set failure status and failure reason.

We have no OpenAPI to force build stop without setting cancelled status.

If you brave, you can use closed api


Kind regards,


Thanks! hardStop() seems to still be canceling the build instead of failing it, but I think runningBuild.addBuildMessage() and setBuildStatus() should be enough to get me the functionality I need. If there is any other way to fail the build and also prevent the build script from being run, please let me know.





Given that you make your check before build has started on build agent, you can use another method to fail build quickly.

Still, this is not OpenAPI

Use call ((RunningBuildManagerEx)runningBuildManager).finishBuild(runningBuild, new Date() /* finish date /, true / should fail */);

RunningBuildManager component you can request as constructor parameter.

Hope this helps,


That solution works for me. Thanks for following up with this, Kirill!


Please sign in to leave a comment.