Run command if and only if tests fail

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

2 Likes

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

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

1 Like

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"
5 Likes

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.

2 Likes