When I run an Execute shell
build step to execute a script and that script returns 0
, Jenkins
flags the build as SUCCESS
, oth
I do it like this:
set +e
./myscript.sh
rc="$?"
set -e
if [ "$rc" == "$EXPECTED_CODE_1" ]; then
#...actions 1 (if required)
exit 0
elif [ "$rc" == "$EXPECTED_CODE_2" ]; then
#...actions 2 (if required)
exit 0
else
#...actions else (if required)
exit "$rc"
fi
echo "End of script" #Should never happen, just to indicate there's nothing further
Here +e
is to avoid default Jenkins behavior to report FAILURE on any sneeze during your script execution. Then get back with -e
.
So that you can handle your exit code as appropriate, else eventually FAIL with the returned code.