Failing a build in Jenkinsfile

oillio picture oillio · Jun 7, 2016 · Viewed 84.6k times · Source

Under certain conditions I want to fail the build. How do I do that?

I tried:

throw RuntimeException("Build failed for some specific reason!")

This does in fact fail the build. However, the log shows the exception:

org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use new java.lang.RuntimeException java.lang.String

Which is a bit confusing to users. Is there a better way?

Answer

StephenKing picture StephenKing · Jun 7, 2016

You can use the error step from the pipeline DSL to fail the current build.

error("Build failed because of this and that..")