Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to add a command line script to Jenkins as part of the build process. This command line script will exit with an error code of 0 if things where successful or 666 if it fails. I wish to stop the build if this script fails.

Is it possible to do this using Jenkins? If so how?

share|improve this question

Your bash build script can set -e prior to running your test.

set -e will cause Jenkins to stop the build if there's a non-zero exit status during the build. You would have something like this in the Execute Shell box in the project configuration:

set -e

Here's some documentation on bash options.

share|improve this answer

You need to be careful exiting with codes above 255. Exit codes must be in the range of 0-255. 0 meaning success the other 1-255 are error codes. You also must avoid reserved error codes which have certain meanings.

cmp@cmp-dev:~$ bash --version
GNU bash, version 4.1.5(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Here is an exit 666:

$ bash
$ exit 666
$ echo $?

It wraps at 255:

$ bash 
$ exit 256
$ echo $?

Stick with 255 and under and avoid reserved error codes (better the devil you know eh?)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.