Is there information available when executing jenkins postbuild script about job status

StackOverflow https://stackoverflow.com/questions/19381124

  •  30-06-2022
  •  | 
  •  

Question

I need to run certain shell command if build fails. Is there any variable passed to shell that contains such info? Or maybe I can find it in file?

I need something like that:

if [ $build_status == "FAIL" ]
  then
    do_the_magic
fi

I have already printed env and there is nothing that would directly say that build failed.

Was it helpful?

Solution

You are looking for the Conditional Build Step Plugin. Add a "Conditional step (single)" as your last build step and use "Current Build Status" for your condition. I like this plugin, but havent't used this particular condition yet.

OTHER TIPS

Same solution explained step by step..Really easy, maybe not to elegant, but it works!

1: Catch all the build result you want to catch (in this case SUCCESS).

2: Inject an env variable valued with the job status

Step 1

3: Do the Same for any kind of other status (in this case I catch from abort to unstable)

enter image description here

4: After you'll be able to use the value for whatever you wanna do.. in this case I'm passing it to an ANT script! (Or you can directly load it from ANT as Environment variable...)

enter image description here

Hope it can help!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top