Run commands on success or failure


#1

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:

after_success:
- "sh beer.sh"
after_fail:
- “sh more-hacking.sh”```


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

Yes please.

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

test:
  override:
    run_test.sh && (send_success_notifications.sh; exit 0) || (run_failure_notifications.sh; exit 1)

This works, but is clunky.


#3

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.


#4

@levlaz what’s the status on this?


#5

Any updates on this?


#6

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


#7

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


#8

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


#9

Thanks for this temporary workaround @Billiam!


#10

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.


#11

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


#12

CircleCI 2.0 closed beta now if you’d like to try it out. https://circleci.com/beta-access/

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


#13

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


#14

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


#15

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

  - run:
      name: Build Success
      when: on_success
      command: |
        if [ "$CIRCLE_NODE_INDEX" == 0 ]; then
          someCommand.sh
        fi
  - run:
      name: Build Failed
      when: on_fail
      command: |
        if [ "$CIRCLE_NODE_INDEX" == 0 ]; then
          someCommand.sh
        fi

#16