CircleCI Slack Orb and status notifications

Viewed 1022

I have been using circleci for a while but I am new with orbs. As you may know, circleci is disabling its current notifications system on August 14th. In consequence, I have been forced to move to orbs. My doubt is about status notifications for each job using circleci/slack@x.y.z

For a SINGLE job, I could do:

jobs:
  build:
    docker:
      - image: <docker image>
    steps:
      - slack/notify:
          channel: CHANNELID
          color: '#42e2f4'
          mentions: 'USERID1,USERID2,'
          message: This is a custom message notification
          webhook: webhook
orbs:
  slack: circleci/slack@x.y.z
version: 2.1
workflows:
  your-workflow:
    jobs:
      - build

But, what happens with multiple jobs. Is there a way to avoid code duplication, repeating under each job steps - slack/notify:

I want to avoid the following

jobs:
  build:
    docker:
      - image: <docker image>
    steps:
      - checkout
      - slack/notify:
          channel: CHANNELID
          color: '#42e2f4'
          mentions: 'USERID1,USERID2,'
          message: This is a custom message notification
          webhook: webhook
  test:
    steps:
      - checkout
      - slack/notify:
          channel: CHANNELID
          color: '#42e2f4'
          mentions: 'USERID1,USERID2,'
          message: This is a custom message notification
          webhook: webhook

  lint:
    steps:
      - checkout
      - slack/notify:
          channel: CHANNELID
          color: '#42e2f4'
          mentions: 'USERID1,USERID2,'
          message: This is a custom message notification
          webhook: webhook

I would appreciate your help as any advice.

1 Answers

Also a long time user I was really keen to the old version of slack notifications.

I found this solution with an old version of the CircleCI Orbs:

orbs:
  slack: circleci/slack@3.4.2.  # version is important

jobs:
  build-and-test:
    docker:
      - image: cimg/node:14.16
    steps:
      - checkout
[...]
      - slack/status:
          fail_only: false
          webhook: $SLACK_WEBHOOK

where $SLACK_WEBHOOK is an CircleCI environment variable configured on a basic slack incoming webhook (or even the one you used to have with the old slack integration!)

NB: the slack/status command is not anymore available on the latest version of the orbs.

It works for us as it only sends a job status in our #build channel on slack, with a visual green or red bar and a link to visit the circle ci page

enter image description here

Related