# Conditional Commands?

**URL:** <https://discuss.circleci.com/t/conditional-commands/30682>\
**Category:** Build Environment\
**Created:** [June 3, 2019, 2:31pm UTC](https://discuss.circleci.com/t/conditional-commands/30682 "2019-06-03T14:31:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimbojsb](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/jimbojsb/32/22464_2.png) [@jimbojsb](https://discuss.circleci.com/u/jimbojsb)\
**Post date:** [June 3, 2019, 2:31pm UTC](https://discuss.circleci.com/t/conditional-commands/30682/1 "2019-06-03T14:31:30Z")

</div>

Is there a way to create a command and then in your step block, add a when: on\_fail? I can’t find a way that passes the config validator.

Use case: we have a custom slack notifier that can DM people via the Github username, and I want to notify build success / failure directly to the individuals, but I can’t get a reusable command to work for that.

---

<div class="post-metadata">

**Author:** ![drazisil](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/drazisil/32/24029_2.png) [@drazisil](https://discuss.circleci.com/u/drazisil)\
**Post date:** [June 5, 2019, 1:39pm UTC](https://discuss.circleci.com/t/conditional-commands/30682/2 "2019-06-05T13:39:48Z")

</div>

Hi Josh! Let me move this to our orbs category for those folks to see and help with 🙂

---

<div class="post-metadata">

**Author:** ![rose](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/rose/32/7816_2.png) [@rose](https://discuss.circleci.com/u/rose)\
**Post date:** [June 5, 2019, 3:14pm UTC](https://discuss.circleci.com/t/conditional-commands/30682/3 "2019-06-05T15:14:22Z")

</div>

@jimbojsb `when: on_fail` is for _steps_, not commands, remember:

[https://circleci.com/docs/2.0/configuration-reference/#run](https://circleci.com/docs/2.0/configuration-reference/#run)

(A command can consist of many steps, so command ≠ step, necessarily.) So, in order to create that for your command, you will need simply add it to every step that is part of your command.

If you’re having issues, you might try dropping your `orb.yml` or `config.yml` here so folks can take a look.

---

<div class="post-metadata">

**Author:** ![jimbojsb](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/jimbojsb/32/22464_2.png) [@jimbojsb](https://discuss.circleci.com/u/jimbojsb)\
**Post date:** [June 5, 2019, 3:54pm UTC](https://discuss.circleci.com/t/conditional-commands/30682/4 "2019-06-05T15:54:58Z")

</div>

What I was trying to do was have a command that does a custom internal notification, and that command takes a recipient and message argument. So when I use that command as a step, I wanted to have that step be on\_fail. Unless I’m misunderstanding how to use commands entirely.

---

<div class="post-metadata">

**Author:** ![drazisil](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/drazisil/32/24029_2.png) [@drazisil](https://discuss.circleci.com/u/drazisil)\
**Post date:** [June 6, 2019, 1:44pm UTC](https://discuss.circleci.com/t/conditional-commands/30682/5 "2019-06-06T13:44:50Z")

</div>

If you share the config.yml for the command it may help, but you can put the `when:` on the steps of the command as Rose said. Then the command will always run, but none of the steps that make it up will. That felt like very awkward English, but maybe it helped?
