Run commands on success or failure


Continuing the discussion from Run command if and only if tests fail:

@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:

- "sh"
- “sh”```

Run command if and only if tests fail
Ability to override tear-down scripts

Yes please.

To get this behavior currently (without causing false positives/negatives), our build config currently looks like this:

  override: && (; exit 0) || (; exit 1)

This works, but is clunky.


This would be super-useful for me. I have a “build” step that I’d like to do between the tests passing and the deployment. It takes a long time and is composed of three commands, so a little too long for a shell pipeline and and little too short for a shell script.


@levlaz what’s the status on this?


Any updates on this?


Really interested in this, it’s a shame we can’t do that at the moment.


We too would love to see this. Used to having this with another CI service and we’re really missing this!


@levlaz any updates on this request?

Would really love to see this feature as it cleans up the pipeline configuration rather than trying to use override on the test command.


Thanks for this temporary workaround @Billiam!


The good news is we will be solving this problem in a first-class way. However, rather than add onto our existing configuration we’ll be adding this as part of an expansion to our new configuration in our “2.0” platform – we’ll be making announcements in the coming months of new features that will dramatically improve on the kind of granular control over your workflow this feature requires.


That’s great news @ndintenfass! When is the 2.0 scheduled for release?


CircleCI 2.0 closed beta now if you’d like to try it out.

I don’t think that feature is ready yet, but a bunch of other things are.


Hey just wondering, is this feature live in CircleCi 2.0 now?


Baffled that this feature isn’t available on a CI platform.


Hey it actually does exist! We use it like this:

  - run:
      name: Build Success
      when: on_success
      command: |
        if [ "$CIRCLE_NODE_INDEX" == 0 ]; then

  - run:
      name: Build Failed
      when: on_fail
      command: |
        if [ "$CIRCLE_NODE_INDEX" == 0 ]; then