3

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?

enter image description here

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?

1 Answers1

3

You may use #!/bin/sh at the start of your Execute shell block as shown below:

enter image description here

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:

enter image description here

Output:

enter image description here

Technext
  • 7,887
  • 9
  • 48
  • 76