I have a groovy script that goes and promotes code. Long story short, I know at a point of time within that script if it was successful or not. I would like to fail the build if not successful. Is there a way in groovy to fail the build?
Example:
in the "execute Groovy script" plugin. you can write code.
(insert API call to promote code)
if(checkPromote()){
//fail build here
}
where 'checkPromote' returns a true or false value depending on the status of the promote.
You can use the error step from the pipeline DSL to fail the current build. error("Build failed because of this and that..") Do you know if that message is stored in a variable like BUILD_NUMBER or JOB_NAME, etc...?
Usage. To create Groovy-based project, add new free-style project and select "Execute Groovy script" in the Build section, select previously configured Groovy installation and then type your command, or specify your script file name.
The most elegant way to abort a programm in my opinion is an assertion.
assert condition : "Build fails because..."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With