00__00__00
00__00__00

Reputation: 5327

setting status of a build in jenkins

I have a jenkins job. It is pretty simple: pull from git, and run the build.

The build is just one step:

Execute window command batch

In my use case, I will need to run some python scripts. Some will fail, some others will not.

python a.py
python b.py

What does determine the final status of the build? It seems I can edit that by:

echo @STABLE > build.proprieties

but how are the STABLE/UNSTABLE status assigned if not specified by the user? What happens if b.py raise an error and fails?

Upvotes: 3

Views: 10223

Answers (1)

Michael Kemmerzell
Michael Kemmerzell

Reputation: 5256

Jenkins interprets a pipeline as failed if a command returns an exit code unequal zero.

Internally the build status is set with currentBuild.currentResult which can have three values: SUCCESS, UNSTABLE, or FAILURE.

If you want to control the failure / success of your pipeline yourself you can catch exceptions / exit codes and manually set the value for currentBuild.currentResult. Plugins also use this attribute to change the result of the pipeline.

For example:

stage {
 steps {
  script {
    try {
        sh "exit 1" // will fail the pipeline
        sh "exit 0" // would be marked as passed
        currentBuild.currentResult = 'SUCCESS'
    } catch (Exception e) {
        currentBuild.currentResult = 'FAILURE'
        // or currentBuild.currentResult = 'UNSTABLE'
    }
  }
}}

Upvotes: 6

Related Questions