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?
You can use the error
step from the pipeline DSL to fail the current build.
error("Build failed because of this and that..")