How to always run a sequential, final job (e.g. Slack notification)?

I’m searching for a solution to run a final job always, i.e. no matter if the previous jobs in a sequence failed. Basically a when: attribute of steps, but as a workflow’s jobs setting:

    - nice-orb/nice-job
    - slack/notify:
          - nice-orb/nice-job
        when: always  # <- This seems not possible, or?

  slack: circleci/slack@3.x  # notify job not there, yet

Without such setting, it would be impossible to use any job of an orb and receiving a notification of the job results with the new UI.


If you are running your jobs sequentially it is not possible to run a final job unconditionally.
As a workaround, you can add a step at the end of every job that uses the when attribute with a value of on_fail to trigger a step that sends a failure message and a final job that sends a success message if none of the previous jobs have failed. This will allow you to trigger a failure message as soon as a job fails and a success message if all jobs run successfully. I hope that’s helpful. Let me know if you have any followup questions. I am happy to help.

Hi @Henna,

thanks for your answer.

Running a final job in a sequential-jobs workflow is a must-have if I want to finally run an orb. E.g. using your slack/notify-orb which is the intended way for Slack-notifications in the new UI.

Your workaround isn’t guaranteed to work for using orbs from someone else, or? Which is a main feature of orbs, isn’t it?

Do you mind clarifying what you mean by using orbs from someone else? Thanks!

@Henna Yes. E.g. in my initial example, I want to use a job from nice-orb from, i.e. that orb is from someone else.

Thank you for clarifying. You can create a job in which you can call commands from another orb and add a the slack status command to send a notification at the end of the job regardless if it passes or fails. For example, I used the hello-build Orb with the Slack Orb.

version: 2.1
    slack: circleci/slack@3.4.2
    hello: circleci/hello-build@0.0.14     
      - image: circleci/node
      - checkout
      - hello/circleci-env-highlights
      - hello/hello-triggerer
      - slack/notify:
        webhook: '${SLACK_WEBHOOK}'
      - my_job

You might also choose to use the when clause together with some Logic Statements to create a workflow that runs jobs when specific conditions are met.

1 Like

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