<commit_before># PagerDuty

The [PagerDuty](http://pagerduty.com/) integration in Buildkite can send [change events](https://developer.pagerduty.com/docs/events-api-v2/send-change-events/) to PagerDuty when your builds finish.

<%= image "overview.png", width: 2202/2, height: 638/2, alt: "Screenshot of the recent events in PagerDuty" %>

{:toc}

## Generating a PagerDuty Integration API Key

Before using the integration you'll need to generate a PagerDuty Integration API Key.

In [PagerDuty](http://pagerduty.com/), go to the "Service Directory":

<%= image "menu.png", width: 854/2, height: 324/2, alt: "Screenshot of the Service Directory link in the menu" %>

Then choose the service you'd like Buildkite to send Change Events to:

<%= image "service-item.png", width: 2842/2, height: 412/2, alt: "Screenshot of the chosen service in the Service Directory" %>

Navigate to the "Integrations" tab and choose "Add a new integration"

<%= image "add-integration.png", width: 2088/2, height: 686/2, alt: "Screenshot of the Add Integration button in PagerDuty" %>

Under "Integration Name", choose a memorable name for this integration. A good example could be the name of the Buildkite pipeline you intend to add this integration to.

For "Integration Type", choose "Buildkite".

Once you've filled out this form, select "Add Integration".

Copy the "Integration Key" from your Integrations list and  use it in [Sending Change Events from your pipeline](#sending-change-events-from-your-pipeline).

<%= image "integration-with-key.png", width: 2262/2, height: 822/2, alt: "Screenshot of the Buildkite integration in PagerDuty" %>

## Sending Change Events from your pipeline

By default, after you've added an Integration API Key, Buildkite will send PagerDuty a Change Event every build regardless of whether the build passed or failed.

Add the PagerDuty [Integration API Key](#generating-a-pagerduty-integration-api-key) to the [`notify` attribute](/docs/pipelines/notifications) of your build configuration:

```yaml
steps:
  - command: "tests.sh"
  - wait
  - command: "deploy.sh"

notify:
  - pagerduty_change_event: "636d22Yourc0418Key3b49eee3e8"
```
{: codeblock-file="pipeline.yml"}

<%= image "change-event.png", width: 2304/2, height: 1096/2, alt: "Screenshot of a Change Event inside PagerDuty sent from Buildkite" %>

To send Change Events only when the build passes, add a [condition](/docs/pipelines/conditionals) to your build configuration:

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

## Support
For those of you coming from [pagerduty.com](https://pagerduty.com) looking for assistance on this integration please reach out to us at <EMAIL>.<commit_msg>Link to nicer PagerDuty Change Events docs<commit_after># PagerDuty

The [PagerDuty](http://pagerduty.com/) integration in Buildkite can send [Change Events](https://support.pagerduty.com/docs/change-events) to PagerDuty when your builds finish.

<%= image "overview.png", width: 2202/2, height: 638/2, alt: "Screenshot of the recent events in PagerDuty" %>

{:toc}

## Generating a PagerDuty Integration API Key

Before using the integration you'll need to generate a PagerDuty Integration API Key.

In [PagerDuty](http://pagerduty.com/), go to the "Service Directory":

<%= image "menu.png", width: 854/2, height: 324/2, alt: "Screenshot of the Service Directory link in the menu" %>

Then choose the service you'd like Buildkite to send Change Events to:

<%= image "service-item.png", width: 2842/2, height: 412/2, alt: "Screenshot of the chosen service in the Service Directory" %>

Navigate to the "Integrations" tab and choose "Add a new integration"

<%= image "add-integration.png", width: 2088/2, height: 686/2, alt: "Screenshot of the Add Integration button in PagerDuty" %>

Under "Integration Name", choose a memorable name for this integration. A good example could be the name of the Buildkite pipeline you intend to add this integration to.

For "Integration Type", choose "Buildkite".

Once you've filled out this form, select "Add Integration".

Copy the "Integration Key" from your Integrations list and  use it in [Sending Change Events from your pipeline](#sending-change-events-from-your-pipeline).

<%= image "integration-with-key.png", width: 2262/2, height: 822/2, alt: "Screenshot of the Buildkite integration in PagerDuty" %>

## Sending Change Events from your pipeline

By default, after you've added an Integration API Key, Buildkite will send PagerDuty a Change Event every build regardless of whether the build passed or failed.

Add the PagerDuty [Integration API Key](#generating-a-pagerduty-integration-api-key) to the [`notify` attribute](/docs/pipelines/notifications) of your build configuration:

```yaml
steps:
  - command: "tests.sh"
  - wait
  - command: "deploy.sh"

notify:
  - pagerduty_change_event: "636d22Yourc0418Key3b49eee3e8"
```
{: codeblock-file="pipeline.yml"}

<%= image "change-event.png", width: 2304/2, height: 1096/2, alt: "Screenshot of a Change Event inside PagerDuty sent from Buildkite" %>

To send Change Events only when the build passes, add a [condition](/docs/pipelines/conditionals) to your build configuration:

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

## Support
For those of you coming from [pagerduty.com](https://pagerduty.com) looking for assistance on this integration please reach out to us at [<EMAIL>](mailto:<EMAIL>?subject=PagerDuty%20Change%20Events%20Integration).
{'fraction_non_alphanumeric': 0.10835579514824797, 'fraction_numerical': 0.030727762803234502, 'mean_word_length': 4.972103004291846, 'pattern_counts': {'":': 2, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1539990', 'n_tokens_mistral': 1913, 'n_tokens_neox': 1714, 'n_words': 645}