Triggering Notifications

The notify attribute allows you to trigger build notifications to different services. You can also choose to conditionally send notifications based on pipeline events like build state.

Add notifications to your pipeline with the notify attribute. This sits at the same level as steps in your pipeline YAML.

For example, to send a notification email every time a build is created:

pipeline.yml
steps:
  - command: "tests.sh"

notify:
  - email: "dev@acmeinc.com"

Available notification types:

  • Email: Send an email to the specified email address.
  • Basecamp: Post a message to a Basecamp Campfire. Requires a Basecamp Chatbot to be configured in your Basecamp organization.
  • Slack: Post a message to the specified Slack Channel. Requires a Slack notification service to be enabled for each channel.
  • Webhooks: Send a notification to the specified webhook URL.
  • PagerDuty

Conditional notifications

To only trigger notifications under certain conditions, add the if attribute.

For example, the following email notification will only be triggered if the build passes:

pipeline.yml
notify:
  - email: "dev@acmeinc.com"
    if: build.state == "passed"

See Build States for possible values for the build state.

To trigger conditional notifications to a Slack channel, you will first need to configure Conditional notifications for Slack.

Email

Add an email notification to your pipeline using the email attribute of the notify yaml block:

pipeline.yml
notify:
  - email: "dev@acmeinc.com"

The email attribute accepts a single email address as a string. To send notifications to more than one address, add each address as a separate email notification attribute:

pipeline.yml
notify:
  - email: "dev@acmeinc.com"
  - email: "sre@acmeinc.com"
  - email: "qa@acmeinc.com"

Email notifications happen at the following event:

  • build finished

Basecamp Campfire Message

To send notifications to a Basecamp Campfire, you'll need to set up a chatbot in Basecamp as well as adding the notification to your pipeline.yml file. Basecamp admin permission is required to setup your chatbot.

Campfire messages can only be sent using Basecamp 3.

  1. Add a chatbot to the Basecamp project or team that you'll be sending notifications to.
  2. Set up your chatbot with a name and an optional URL. If you'd like to include an image, you can find the Buildkite logo in our Brand Assets.
  3. On the next page of the chatbot setup, copy the URL that Basecamp provides in the curl code snippet
  4. Add a Basecamp notification to your pipeline using the basecamp_campfire attribute of the notify yaml block and the URL copied from your Basecamp chatbot:
pipeline.yml
notify:
  - basecamp_campfire: "https://3.basecamp.com/1234567/integrations/qwertyuiop/buckets/1234567/chats/1234567/lines"

The basecamp_campfire attribute accepts a single URL as a string.

Basecamp notifications happen at the following events, unless you restrict them using conditionals:

  • build created
  • build started
  • build blocked
  • build finished
  • build skipped

Slack Channel and Direct Messages

If you need fine-grained control over your notifications, or want to send notifications triggered by non-build events, the Slack Notification Service can be extended using the notify attribute.

If you only need to send notifications on build status events, you can set this up in Buildkite using your Slack Notification Service's 'Build State Filtering' settings.

Before adding a notify attribute to your pipeline.yml, ensure an organization admin has set up a Slack integration for the channel or user that you want to post to. For detailed information about setting up a Notification Service, see the Slack integration page.

Once a slack channel has been configured in your organization, add a Slack notification to your pipeline using the slack attribute of the notify yaml block.

When using just a channel name, you must specify it in quotes, as otherwise the # will cause the channel name to be treated as a comment.

For example, to deliver notifications to the #general channel of all configured workspaces:

pipeline.yml
notify:
  - slack: "#general"

For example, to deliver notifications to user @someuser in all configured workspaces:

pipeline.yml
notify:
  - slack: "@someuser"

To send a notification to one particular workspace and channel or workspace and user, specify the workspace name as well:

For channels

pipeline.yml
notify:
  # Notify channel
  - slack: "buildkite-community#general"
  # Notify user
  - slack: "buildkite-community@someuser"

You can also specify multiple teams and channels with the channels attribute:

pipeline.yml
notify:
  - slack:
      channels:
        - "buildkite-community#sre"
        - "buildkite-community#announcements"
        - "buildkite-team#monitoring"
        - "#general"

To add a custom message to the notification:

pipeline.yml
notify:
  - slack:
      channels:
        - "buildkite-community#sre"
      message: "SRE related information here..."
  - slack:
      channels:
        - "buildkite-community#announcements"
      message: "General announcement for the team here..."

You can also add conditionals to restrict the events on which notifications are sent:

pipeline.yml
notify:
  - slack: "#general"
    if: build.state == "passed"

See Build States for possible values for the build state.

Slack notifications happen at the following event:

  • build finished

Webhooks

Send a notification to a webhook URL from your pipeline using the webhook attribute of the notify yaml block:

pipeline.yml
notify:
  - webhook: "https://webhook.site/32raf257-168b-5aca-9067-3b410g78c23a"

The webhook attribute accepts a single webhook URL as a string. To send notifications to more than one endpoint, add each URL as a separate webhook attribute:

pipeline.yml
notify:
  - webhook: "https://webhook.site/82n740x6-168b-5aca-9067-3b410g78c23a"
  - webhook: "https://webhook.site/32raf257-81b6-9067-5aca-78s09m6102b4"
  - webhook: "https://webhook.site/27f518bw-9067-5aca-b681-102c847j917z"

Webhook notifications happen at the following events, unless you restrict them using conditionals:

  • build created
  • build started
  • build blocked
  • build finished

PagerDuty Change Events

If you've set up a PagerDuty integration you can send Change Events from your pipeline using the pagerduty_change_event attribute of the notify yaml block:

pipeline.yml
steps:
  - command: "tests.sh"

notify:
  - pagerduty_change_event: "636d22Yourc0418Key3b49eee3e8"

Email notifications happen at the following event:

  • build finished

Restrict notifications to passed builds by adding a conditional:

pipeline.yml
steps:
  - command: "tests.sh"

notify:
  - pagerduty_change_event: "636d22Yourc0418Key3b49eee3e8"
    if: "build.state == 'passed'"

Build States

Build state can be one of creating, scheduled, running, passed, failed, blocked, canceling, canceled, skipped, not_run, or finished. finished is a shortcut for a build of passed, failed, blocked, and canceled state.

See the full build states diagram for more information on how builds transition between states.

Job states

Job state can be one of pending, waiting, waiting_failed, blocked, blocked_failed, unblocked, unblocked_failed, limiting, limited, scheduled, assigned, accepted, running, finished, canceling, canceled, timing_out, timed_out, skipped, or broken.

See the full job states diagram for more information on how jobs transition between states.