Notifications

Overview

Notifications are triggered at the end of your entire build. If you are running a matrix build the notification is sent after all matrix jobs complete.

Example Slack notification using the Slack plugin:

---
notify:
  slack:
    webhook_url: https://hooks.slack.com/services/...
    channel: dev
    username: drone

Please note notifications are executed after a build is already terminated and will not write any output to your build logs. For troubleshooting failed notifications please contact your system administrator to research errors in the Drone server logs.

Plugins

Drone does not have any builtin notification capabilities. Drone instead offers a large library of plugins for sending Slack, Hipchat, Email notifications and more. Please see the plugin documentation for a complete list.

Conditions

Use the when block to limit notification step execution:

---
notify:
  slack:
    channel: foo
    when:
      success: false
      failure: false
      change: true

Execute a notification step if the branch is master:

---
notify:
  slack:
    channel: foo
    when:
      branch: master

Execute a notification step if the branch is master or develop:

---
notify:
  slack:
    channel: foo
    when:
      branch: [master, develop]

Execute a notification step if the branch is not develop:

---
notify:
  slack:
    channel: foo
    when:
      branch: "!develop"

Execute a notification step if the branch is starts with prefix/*:

---
notify:
  slack:
    channel: foo
    when:
      branch: prefix/*

Execute a notification step when the commit is a pull_request, push or tag:

---
notify:
  slack:
    channel: foo
    when:
      event: pull_request

Define the same notification step multiple times, using different configuration based on branch:

---
notify:
  slack:
    channel: foo
    when:
      branch: develop

  slack:
    channel: bar
    when:
      branch: master

Templates

Many of the Drone notifications support handlebars templates for customizing notification messages. This example demonstrates a custom hipchat notification message:

---
notify:
  hipchat:
    template: |
      {{ repo.full_name }} finished build {{ build.number }}
      with a status of {{ build.status }}

Example template that generates a different message based on build status:

---
notify:
  hipchat:
    template: |
      {{#success build.status}}
        {{ build.author }} successfully pushed to {{ build.branch}}
      {{else}}
        {{ build.author }} broke the build. Hang your head in shame.
      {{/success}}

Template Data

This is an example data structure passed to the template engine. Any of the below variables may be referenced in your template:

{
    "build": {
        "number": 22,
        "status": "success",
        "started_at": 1421029603,
        "finished_at": 1421029813,
        "event": "push",
        "commit": "7fd1a60",
        "branch": "master",
        "message": "Update README",
        "author": "octocat",
        "author_email": "[email protected]",
        "link_url": "https://github.com/octocat/Hello-World/commit/7fd1a60"
    },
    "repo": {
        "owner": "octocat",
        "name": "hello-world",
        "full_name": "octocat/hello-world",
        "link_url": "https://github.com/octocat/hello-world",
        "clone_url": "https://github.com/octocat/hello-world.git"
    },
    "system": {
        "link_url": "https://drone.mycompany.com"
    }
}

Template Builtins

Drone includes a number of builtin handlebars functions to help format your messages. This is an example builtin function that converts a string to all uppercase characters:

{{uppercase build.status}}

Converts a string to all lowercase characters:

{{uppercase build.author}}

Truncates a string to N characters:

{{ truncate build.commit 8 }}

Calculates a duration and returns a human readable string:

{{ duration build.started_at build.finished_at }}

Converts a timestamp to a human readable string:

finished at {{ datetime build.finished_at "3:04PM" "UTC" }}

Returns true if the build is successful:

{{#success build.status}}
  It works
{{/success}}

Returns true if the build failed:

{{#failure build.status}}
  Something is busted
{{/failure}}
This website is a public GitHub repository, which is forked from upstream Drone CI documentation. Please help us by forking and improving upstream Drone CI documentation or Tea CI documentation.