2

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?

Gary Willoughby
  • 102
  • 2
  • 11

2 Answers2

2

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
yourcommand1
yourcommand2

Here's some documentation on bash options.

cjc
  • 24,916
  • 3
  • 51
  • 70
2

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 <http://gnu.org/licenses/gpl.html>

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
exit
$ echo $?
154

It wraps at 255:

$ bash 
$ exit 256
exit
$ echo $?
0

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

Jeff Snider
  • 3,272
  • 18
  • 17
gm3dmo
  • 10,057
  • 1
  • 42
  • 36