Slack notifications for workflows should include job names

slack
workflow
2.0

#1

I just switched over one of our projects to use workflows. One of the downsides is that our slack notifications are now very noisy. Rather than one notification for a passed or failed build, we get a notification for each job in the workflow, with the same text.

Ideally, when a workflow is being run, the slack notification for a build would include the following information (new fields in bold):

  • build status
  • workflow id
  • link to workflow
  • job name
  • build number
  • link to build
  • project name
  • branch
  • commit log oneline

It would be particularly nice if slack notifications could be configured do work differently for workflow-enabled jobs. If all is well with the workflow, then I’d like a single notification for the success of the workflow. If a job fails within a workflow, then a slack notification could be sent linking directly to the failed build.

This also relates to this ticket: Build names in workflows


Workflow Webhooks job names are missing
#2

This would be awesome. I just muted my slack because of this ;-D

@CircleCI-Employees When can we expect an update on this bug?


#3

Duplicate here also:


#4

Is the slack notifier source code available anywhere? I would consider contributing a pull request to add this functionality, if it was possible to do so.


#5

I need this feature for HipChat notifications as well


#6

We also really need this feature. The very minimum is to post a job name in the hook, otherwise it’s just duplicate notifications.


#7

Very annoying. Same problem for emails and probably other integrations.


#8

Yeah, this would be a FINE addition for sure. Maybe folks not using workflows don’t notice it, but in flows where multiple build statuses are returning, it’s obnoxious.

If there’s no timeline on this, it at least be nice to know if there’s an implementation possibility in the script or with custom webhooks.


#9

I ended up removing the slack notifications from CircleCI and building a script to notify directly:

  • in the first job in the first step after checking the code out,
  • in the last job: on the last step,
  • in every job, in a step with “when: on_fail”, to get errors if the job fails.

The core of the (bash) script is this function:

# Send notification to Slack channel
function send_slack_notification() {
    local channel=$1
    local mesg=$2
    local user=$3
    res=$(curl -s \
        -X POST \
        -d "token=${SLACK_TOKEN_OX:-}" \
        -d "channel=${channel}" \
        -d "text=${mesg}" \
        -d "username=${user}" \
        -d "icon_url=https://a.slack-edge.com/41b0a/img/plugins/circleci/service_48.png" \
        https://slack.com/api/chat.postMessage
    )
    if [[ "$(echo ${res} | jq '.ok')" == "false" ]]; then
        echo "Error sending Slack notification: $(echo ${res} | jq -r '.error')."
        exit 1
    fi
    echo "Sent Slack notification to ${channel}."
}

#10

We would also love to see this, or an official workaround. @kenden - do you have a more complete example perhaps in a GitHub Gist?


#11

We did the same thing and also moved to an on_fail step that sends a Slack announcement. However, we didn’t see any environment variable that contained the job name. How do you determine that?


#12

Cast your vote for this feature in the new “Feature Requests”/Ideas portal


#13