Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does jenkins consider this build step as passed?

Tags:

jenkins

perl

#!/bin/sh
date;
perl aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.pl
date;

The script does not exist and it should fail.

like image 236
David Michael Gang Avatar asked Dec 07 '25 00:12

David Michael Gang


2 Answers

Exit status (0 is success, everything else is failure) of script is exit status of last command. To fix, store the right exit status in shell variable before doing something else. Example:

#!/bin/sh
date
perl aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.pl
perlexitstatus=$?
date
exit $perlexitstatus

For completeness, two other ways:

#!/bin/sh
set -e # exit on non-zero command exitcode
date
perl aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.pl
date

Above is often a bit inconvenient, because often shell script has commands you don't care about, and don't want the script to fail for them.

#!/bin/sh
set -e # exit on non-zero command exitcode
date
perl aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.pl ||
    { echo "aaaa... Script failed, spam [email protected]"; exit 1;}
date

Last one could be written with if-then-fi statement too, if preferred. It provides a way to print custom error message, in case the failing command's message is unclear.

like image 98
hyde Avatar answered Dec 08 '25 16:12

hyde


If you set shebang with a shell you could provide -e parameter to make script break on inner command failures:

#!/bin/sh -e
date;
perl aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.pl
date;
like image 27
Sergey Grinev Avatar answered Dec 08 '25 14:12

Sergey Grinev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!