Reputation:
I want to be able to read the exit code of the build script, from my post-build script. Is there a way to do that in Jenkins configuration?
it will allow me to check for a matching string (in this case 'hella success rn') but it won't let me see the exit code of the build script?
Upvotes: 3
Views: 601
Reputation: 8107
You may use #!/bin/sh
at the start of your Execute shell
block as shown below:
Using #!/bin/sh
without the default options that Jenkins uses i.e., #!/bin/sh -xe
will prevent Jenkins from marking your Execute shell
as failure. Doing this will help you run the subsequent command of finding the return status of your script.
-e Exit immediately if a command exits with a non-zero status.
Ref: http://linuxcommand.org/lc3_man_pages/seth.html
Based on the return status (script_status=$?
) of your script, print something that you can search later in your post-build step.
Then, in the Post-build Actions
, search that printed text to decide your post-build action as shown below:
Output:
Upvotes: 3