Notifying Continuous Integration failure/success status on Email & Slack

- By Abhijit Kini on May 27, 2016

Notifications are particularly useful when you start hitting scale with the number of software projects that are being worked on in parallel. Having the flexibility to configure the Continuous Integration platform to be notified for different scenarios becomes critical, in my opinion, in helping to reduce technical debt

At Shippable, we use Slack extensively for our internal communications. It allows us to be more efficient, communicate faster and have targeted discussions. One of the scenarios we use Slack is to monitor and discuss build issues based on the build status of critical projects. An example shown below.

Notifying continuous integration status on Slack

 

In this tutorial, I'll pick three scenarios and go over configuring notifications for a Continuous Integration project status on email and Slack. First I'll go over the basics of the shippable.yml file configuration for email/Slack notifications. Then I'll cover the scenarios for email and Slack.

Before you begin

Ensure you have:

Scenarios for Notifications

I'll pick three scenarios outlined below, to configure CI notifications on the Shippable platform.

  1. Send notification of the build results of the 'Master' branch to john.smith@foo.com, last committer and the project owner.
  2. Never send any notification of the build results of the 'Test' branch.
  3. Send notification of the successful and failed build results only of the 'Master' branch to a Slack channel shippable-tutorials.

Basic shippable.yml structure for notifications

Let's first review a sample shippable.yml file and understand the different sections related to notifications.

integrations:
  notifications:
    - integrationName: email
      type: email
      recipients:
        - exampleone@org.com
        - exampletwo@org.com
          branches:
            only:
              - master
              - dev
          on_success: change
          on_failure: always

- integrations: This section in the shippable.yml file is used for integrations such as notifications and hub.

- notifications: Specifies that the subsequent code is related to notifications.

- integrationName: Default value is email. For Slack, HipChat and IRC, you can specify a custom name. The custom name should match what you specify in the UI.

- type: Options are email, slack, hipchat and irc.

- recipients: Under this section is where you specify where the notifications should be delivered. It is email addresses for email; channels for Slack; rooms/users for HipChat; rooms/channels for IRC. By default the 'last committer' and the 'project owners' are notified, if this section is not configured.

- branches: An optional setting, allows you to specify the branches of your project to be notified. By default, notifications are sent to all branches. Use the 'only' tag to send notifications about specific branches only and 'except' tag to exclude specific branches from sending notifications.

- on_success: An optional setting, allows you to specify notification actions based on a successful build. The values for this field are - always, never and change. The default value is 'change', which means only when the build status changes to success, the notification action will be triggered. For more than one successive, successful builds, the notification action is triggered only for the first one.

- on_failure: An optional setting, allows you to specify notification actions based on a failed build. The values for this field are - always, never and change. The default value is 'always', which means a notification is always triggered whenever there is a failed build.

- on_start: An optional setting, allows you to specify notification actions during the start of the build process. The values for this field are - always and never. The default value is 'never', which means a notification is never triggered at the start of any build for that project.

- on_pull_request: An optional setting, allows you to specify notification actions for pull requests. The values for this field are - always and never. The default value is 'always', which means a notifications is always triggered when a pull request is initiated for the project.

Configuration for Email

I'll configure email notifications for the first two scenarios outlined.

  1. Send notification of the build results of the 'Master' branch to john.smith@foo.com, last committer and the project owner.
    • Here's how I'll configure the shippable.yml file for the Node.js project.
      Shippable yml file for notifying continuous integration status on email

  2. Never send any notification of the build results of the 'Test' branch.
    • Here's how I'll configure the shippable.yml file
      Shippable yml file for notifying continuous integration status on email

 

Configuration for Slack

Configuring an incoming webhook on Slack:

- Sign in to your Slack account and access this link to create an incoming webhook.

- Pick any channel to create the webhook. It will be overridden in the next step, when you configure the integration on Shippable.

- Get the webhook URL. In this case I have: https://hooks.slack.com/services/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

Set up Slack integration on Shippable:

- Click on 'Account Settings' (the gear icon on the top, right hand)

- Click on the 'Integrations' tab

- Click 'Add Integration'

- In the 'Master Integration' dropdown select 'Slack'

- Give a name to the Slack integration. In this case I'll use 'Shippable-Slack'

- Input the 'Webhook URL'

- Put the channel name 'shippable-tutorial' in this case

- Click 'Save'

Slack integration for a CI project

Ensure this Slack integration is configured for the sample_nodejs project

  • Go to the 'Project settings'.
  • Scroll down to the 'Notification Integration' drop down & select 'Shippable-Slack' integration for this project.

Slack integration for a CI project 

Now that I've configured the Slack integration, I'll configure the shippable.yml file for the third scenario.

3. Send notification of the successful and failed build results only of the 'Master' branch to a Slack channel shippable-tutorials.

  • Here's how I'll configure the shippable.yml file

Shippable yml file for Slack integration to be notified of CI status

Upon committing code for a successful and failed build, the 'tutorial' Slack channel is notified as shown below:

Successful configuration of Slack displaying Continuous Integration status

With this Email and Slack integrations, you can now be on top of the build status for your Continuous Integration projects. Here's a bonus - Shippable also supports HipChat and IRC notifications too!!

Having these integrations enables strong collaboration between developer teams thereby helping reduce the 'technical debt' in your organization. 


Try Shippable

Topics: continuous integration (CI), nodejs, Slack, Notifications