Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to mark a build unstable in Jenkins when running shell scripts

In a project I'm working on, we are using shell scripts to execute different tasks. Some are sh/bash scripts that run rsync, and some are PHP scripts. One of the PHP scripts is running some integration tests that output to JUnit XML, code coverage reports, and similar.

Jenkins is able to mark the jobs as successful / failed based on exit status. In PHP, the script exits with 1 if it has detected that the tests failed during the run. The other shell scripts run commands and use the exit codes from those to mark a build as failed.

// :: End of PHP script: // If any tests have failed, fail the build if ($build_error) exit(1); 

In Jenkins Terminology, an unstable build is defined as:

A build is unstable if it was built successfully and one or more publishers report it unstable. For example if the JUnit publisher is configured and a test fails then the build will be marked unstable.

How can I get Jenkins to mark a build as unstable instead of only success / failed when running shell scripts?

like image 523
HNygard Avatar asked Nov 16 '11 07:11

HNygard


People also ask

How do you mark a level as unstable Jenkins?

To mark only specific stages as unstable, use the step unstable(message: String) as described here within your stage and install/update the following plugins: Pipeline: Basic Steps to 2.16 or newer. Pipeline: API Plugin to 2.34 or newer. Pipeline: Groovy to 2.70 or newer.

How do I make my Jenkins unstable?

In Jenkins Terminology, an unstable build is defined as: A build is unstable if it was built successfully and one or more publishers report it unstable. For example if the JUnit publisher is configured and a test fails then the build will be marked unstable.

Which Colour ball in the build status refers to an unstable build?

An amber ball in the build status refers to an unstable build.


1 Answers

Modern Jenkins versions (since 2.26, October 2016) solved this: it's just an advanced option for the Execute shell build step!

exit code for build

You can just choose and set an arbitrary exit value; if it matches, the build will be unstable. Just pick a value which is unlikely to be launched by a real process in your build.

like image 109
Alan Franzoni Avatar answered Oct 04 '22 17:10

Alan Franzoni