Run command if and only if tests fail


#1

Is there a way to run a command if and only if my build tests fail?


#2

This is not supported out of the box, if your tests fail and return a non zero exit code the entire build stops.

What you could do is wrap your entire test suite in a simple script that checks for the success or failure, and then fires off your command in the event of failure. As long as that script returns a zero exit code, then the entire build will pass.

Best,
Lev


#3

@levlaz Thanks for getting back to me! I’ll do this using a script, as you suggested.


#4

Just to be explicit, that means the test: post: command runs after every build right?

@levlaz I think this would be useful, having specific hooks for after_fail and after_success. These seem like very common operations to me.

I’d love to see something like:

test:
  after_success: 
    - "sh beer.sh"
  after_fail:
    - "sh more-hacking.sh"

Run commands on success or failure
#5

This is a great idea, I made this a feature request Run commands on success or failure, be sure to show your support for this feature by clicking on the heart.


#6