# Make custom command run always with \`when: always\`

**URL:** <https://discuss.circleci.com/t/make-custom-command-run-always-with-when-always/38957>\
**Category:** Build Environment\
**Created:** [January 29, 2021, 11:22pm UTC](https://discuss.circleci.com/t/make-custom-command-run-always-with-when-always/38957 "2021-01-29T23:22:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![levinotik](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/levinotik/32/26570_2.png) [@levinotik](https://discuss.circleci.com/u/levinotik)\
**Post date:** [January 29, 2021, 11:22pm UTC](https://discuss.circleci.com/t/make-custom-command-run-always-with-when-always/38957/1 "2021-01-29T23:22:29Z")

</div>

I have a circle config which includes the following custom command:

```auto
  remove-circle-ip:
    description: "remove current Circle CI box IP from inbound security group rules for DB"
    steps:
      - aws-white-list-circleci-ip/remove:
          tag-key: circleci
          tag-value: whitelistmeplease
          port: 5432

```

which I use in my job as follows:

```auto
jobs:
  test:
    docker:
      - image: nikolaik/python-nodejs:python3.8-nodejs12
        environment:
          AWS_DEFAULT_REGION: us-east-2
    steps:
      - setup
      - install-python-deps
      - add-circle-ip
      - run:
          name: run tests
          command: |
            poetry run coverage run --source='.' manage.py test 
      - run:
          name: remove circle IP
          command: remove-circle-ip
          when: always

```

I’d like the `remove circle IP` to run even if the tests which run before it fail. I can’t seem to figure out the syntax for this. Previously, I had just used `- remove-circle-ip` to run the command rather than putting a `run` block, i.e.:

```auto
jobs:
  test:
    docker:
      ...
    steps:
      - setup
      - ...
      - add-circle-ip
      - ...
      - remove-circle-ip

```

but couldn’t figure out how to specify `when: always` if I did it that way.

But now, when switching to run, it fails with “remove-circle-ip: command not found”

So how can I make this command always run even if steps before fail?

---

<div class="post-metadata">

**Author:** ![nbialostosky](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/nbialostosky/32/24962_2.png) [@nbialostosky](https://discuss.circleci.com/u/nbialostosky)\
**Post date:** [February 1, 2021, 2:58pm UTC](https://discuss.circleci.com/t/make-custom-command-run-always-with-when-always/38957/2 "2021-02-01T14:58:30Z")

</div>

Hi @levinotik – welcome to Discuss!

Is the `remove-circle-ip` command invoking an Orb? Or is the command using another already specified command?

The `when: always` will essentially need to get added at the base level of the run step. If you are using an Orb that may require changing the Orb. If you can provide a link to the failed build you mentioned I can look at your config file and provide a bit more information. If you don’t feel comfortable posting the build link here you can [submit a ticket](https://support.circleci.com/hc/en-us/requests/new) and mention this post and I will pick up that ticket.

Thanks!

---

<div class="post-metadata">

**Author:** ![levinotik](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/levinotik/32/26570_2.png) [@levinotik](https://discuss.circleci.com/u/levinotik)\
**Post date:** [February 3, 2021, 10:11pm UTC](https://discuss.circleci.com/t/make-custom-command-run-always-with-when-always/38957/3 "2021-02-03T22:11:16Z")

</div>

hey, thanks for the reply. I got this to work by switching the `run` to a `when` block as follows:

```python
  - when:
      condition:
        equal: [42, 42] # a value that is always true
      steps:
        - remove-circle-ip

```

---

<div class="post-metadata">

**Author:** ![nbialostosky](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/nbialostosky/32/24962_2.png) [@nbialostosky](https://discuss.circleci.com/u/nbialostosky)\
**Post date:** [February 4, 2021, 2:24pm UTC](https://discuss.circleci.com/t/make-custom-command-run-always-with-when-always/38957/4 "2021-02-04T14:24:11Z")

</div>

Awesome, thanks for the reply on how you ended up solving this!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/circleci/original/3X/5/1/511608acda8e85906e15909b57bd0a46c1dbe291.png) [@system](https://discuss.circleci.com/u/system)\
**Post date:** [February 14, 2021, 2:24pm UTC](https://discuss.circleci.com/t/make-custom-command-run-always-with-when-always/38957/5 "2021-02-14T14:24:31Z")

</div>

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
