user12374570
user12374570

Reputation:

How to do a post-build task based off the exit code of the build script?

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?

Upvotes: 3

Views: 601

Answers (1)

Technext
Technext

Reputation: 8107

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

Upvotes: 3

Related Questions