Skip to main content

Create PagerDuty Incidents from Failed Tests

With the PagerDuty webhook template, TestingBot opens an incident in PagerDuty the moment a test fails. Your on-call engineer is paged with the test name, browser, platform and a direct link to the test details page, so the failure can be investigated right away.

The template uses the PagerDuty Events API v2: you only need a routing key, no PagerDuty user account credentials are involved.

Prerequisites

You need an Events API v2 routing key from PagerDuty:

  1. In PagerDuty, open the service that should receive the incidents (or create a new one).
  2. On the service page, go to the Integrations tab and add an Events API v2 integration.
  3. Copy the Integration Key (also called the routing key) that PagerDuty generates.

The webhook URL is always the fixed PagerDuty endpoint https://events.pagerduty.com/v2/enqueue; the routing key inside the payload determines which service receives the event.

Set up the webhook in TestingBot

  1. Log in to the TestingBot member area and open the Webhooks page under Integrations.
  2. Click Create webhook and give it a name, for example PagerDuty incidents.
  3. Under Start from a template, pick the PagerDuty tile. This prefills the URL https://events.pagerduty.com/v2/enqueue, the POST method and the payload below.
  4. In the Body tab, replace YOUR_PAGERDUTY_ROUTING_KEY with the Integration Key you copied from PagerDuty.
  5. Set the trigger to failures only, so an incident is created only when a test fails. Optionally narrow it down with a test type or a name filter such as regression_*.
  6. Click Create webhook at the bottom of the form to save the configuration.

Template payload

The PagerDuty template sends this JSON body. Replace YOUR_PAGERDUTY_ROUTING_KEY with your own routing key; the {{...}} tokens are substituted with test values at delivery time and are documented on the built-in variables page.

{
  "routing_key": "YOUR_PAGERDUTY_ROUTING_KEY",
  "event_action": "trigger",
  "payload": {
    "summary": "Test {{TEST_STATUS}}: {{TEST_NAME}}",
    "source": "TestingBot",
    "severity": "error",
    "custom_details": {
      "browser": "{{BROWSER_NAME}} {{BROWSER_VERSION}}",
      "platform": "{{PLATFORM}}",
      "duration_sec": {{TEST_DURATION}},
      "tags": {{TEST_TAGS}}
    }
  },
  "links": [
    { "href": "{{TEST_URL}}", "text": "View test on TestingBot" }
  ]
}

The incident summary contains the test result and name, the custom details carry the browser, platform, duration and tags, and the attached link opens the test on TestingBot. Everything stays editable: you can change the severity, add a dedup_key or extend custom_details with more variables.

Test it

Click Test Webhook in the form to send a sample event with placeholder test values. The response panel shows the HTTP status, duration, headers and body returned by PagerDuty; a successful request returns a 2xx status with "status": "success" in the body, and a new incident appears on the PagerDuty service you connected.

If no incident shows up, check these common causes:

  • The routing key is wrong or still set to the YOUR_PAGERDUTY_ROUTING_KEY placeholder; PagerDuty responds with a 4xx status in that case.
  • The integration was created on a different service than the one you are watching.
  • The service in PagerDuty is disabled or in maintenance mode.
Was this page helpful?
Last updated