Skip to main content
A flaky test gets fixed fastest when the team that owns it hears about it right away. Trunk already knows each test’s code owners from your CODEOWNERS file. This recipe uses that to route every newly flaky test to its owners: it files a ticket in your tracker, assigns it to the team, and posts in the team’s Slack channel. It’s a small service you run yourself, built from one webhook and two API calls:
If you only need tickets, and not per-team routing or Slack messages, automatic ticketing does it with no code.

Before you begin

You need:
  • A ticketing integration set as the test collection’s default. Connect Jira, Linear, or Asana, and select it in the collection’s ticketing settings. Without a default, creating a ticket fails with TICKETING_NOT_CONFIGURED.
  • An API key with the Create tickets permission. See Create an API key. Reading tests needs no permission.
  • A Slack bot token with the chat:write scope, and the bot invited to each team’s channel.
  • A webhook endpoint subscribed to v2.test_case.status_changed, pointed at the service you build below. See Webhooks to add one, and copy its signing secret.

1. Map code owners to teams

Trunk returns each test’s owners exactly as they appear in your CODEOWNERS file, such as @acme/payments. Keep a map from those owners to where each team wants to hear about flaky tests:
Mentioning the team’s Slack user group is what makes the message an assignment and not just a notification.

2. Receive the webhook

Verify the signature, then act only when a test moves into the flaky state. Respond quickly and do the work in the background, so a slow ticket call doesn’t time out the delivery:

3. Read the test

Fetch the test before acting. Webhooks can arrive late or be retried, so this confirms the test is still flaky, gets its owners, and shows whether a ticket is already linked. Adding include=metrics returns its recent failure rate for the Slack message:
The fields this recipe uses:

4. File and assign a ticket

Call Create a ticket for a test. Trunk files the ticket in the collection’s default ticketing integration, writes the title and description, and links the ticket to the test. The description includes the test’s location, failure rate, owners, and most common failure reasons. Set the assignee through fields, using the shape your tracker expects. Anything you pass is merged over the default fields saved on the integration:
The response is the linked ticket, including its key, url, status, and assignee.
Don’t retry a 504 blindly. The ticket can be filed after the call times out, so read the test first: if its ticket is set, the ticket exists.

5. Tell the owning team

Post to the team’s channel with the test, why it was flagged, and the ticket:

Put it together

A test can list several owners. This picks the first one found in your map. To notify every owning team instead, post once per matching owner and keep the single ticket, since a test carries at most one.

Test it

You don’t have to wait for a test to turn flaky. Find a flaky test with List and search tests, then call routeFlakyTest with its id:
To test the whole path, including signature checks, send an example v2.test_case.status_changed event from your webhook endpoint’s Testing tab.

Troubleshooting