How to customize your Slack messages when using CircleCI's Slack Orb

 

If you would like to customize Slack messages to represent CircleCI and include important build information. Below is a template using markdown to get you started.

Tips

You can also change the name of your slack bot user to "CircleCI". You can do this by navigating to https://api.slack.com/apps/ > your app > Display Information > App name

You can update your app icon to include a CircleCI logo. You can find CircleCI logos and Icons here: https://brandfolder.com/circleci

Solution with example

The following code shows an example of setting a slack notification with a custom message which is triggered when the job fails due to the event: fail setting being set:

     - slack/notify:
          event: fail
          custom: | 
            {
                "blocks": [
                    {
                        "type": "section",
                        "text": {
                            "type": "mrkdwn",
                            "text": "Failed: $CIRCLE_USERNAME's build of \n<$CIRCLE_BUILD_URL|$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME>\n(<https://app.circleci.com/pipelines/github/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME?branch=$CIRCLE_BRANCH|$CIRCLE_BRANCH>) \n- <$CIRCLE_BUILD_URL|$CIRCLE_JOB> failed" 
                        }
                    }
                ]
            }  

Once this code is triggered on a failed build it will send the text set within the text section using markdown with the text that has been set.

You might also find it useful to use one of CircleCI's pre-built message templates which you can find here.

Additionally, you can find the source code to these pre-build message templates here:  https://github.com/CircleCI-Public/slack-orb/tree/master/src/message_templates

You can build your own custom templates using Slack's BlocK Kit Builder .

Was this article helpful?
1 out of 4 found this helpful

Comments

0 comments

Please sign in to leave a comment.