Jenkins build error from groovy script

I have a groovy script that goes and promotes the code. In short, I know at some point in this script if it was successful or not. I would refuse to build if I was not successful. Is there a way in groovy build failure?

Example:

in the "execute groovy script" plugin. you can write the 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 advertiser.

+4
source share
4 answers

The most elegant way to interrupt a program, in my opinion, is a statement.

assert condition : "Build fails because..."

+7
source

There is an error step in the dsl declarative pipeline:

error('Failing build because...')

https://jenkins.io/doc/pipeline/steps/workflow-basic-steps " ".

:

sh "exit 1"
+2

I usually use something simple, like this throw new Exception("Error Message"), so maybe you can try:

    if(checkPromote()){
         throw new Exception("Error Message")
     }

Hope this also works for you.

0
source

On this page https://wiki.jenkins-ci.org/display/JENKINS/Groovy+plugin

import hudson.AbortException
//other code
throw new AbortException("Error message .")
0
source

Source: https://habr.com/ru/post/1674783/


All Articles