Jira integration

Learn how to automatically create Jira issues with Flaky Test webhooks

Trunk allows you to automate Jira issue creation through webhooks. When a test becomes flaky and impacts enough PRs, a Jira issue is created automatically with full context including failure rates, ownership, and stack traces.

This guide will walk you through integrating Trunk Flaky Tests with Jira through webhooks. You will be able to automatically generate Jira issues for new flaky tests found in your repo that impact more than 2 PRs. This guide should take 15 minutes to complete.

Trunk also has a built-in Jira integration for manual ticket creation. You only need to use webhooks if you want to automate ticket creation or need additional customization.

1. Create a Jira API Token

Before you can create a webhook to automate Jira issue creation, you need to create an API token to authorize your requests.

  1. Click Create API token, give it a label (e.g., "Trunk Webhooks"), and click Create.

  2. Copy the token and save it in a secure location. You'll need it later.

You'll also need to generate a Base64-encoded credential string for authentication. Run this in your terminal:

echo -n "[email protected]:your-api-token" | base64

Replace [email protected] with the email associated with your Jira account and your-api-token with the token you just created. Save the output for step 3.

2. Add a new webhook in Trunk

Trunk uses Svix to integrate with other services, such as creating Jira issues through webhooks.

You can create a new endpoint by:

  1. From your profile on the top right, navigate to Settings

  2. Under Organization > Webhooks, click Automate Jira Issues Creation.

  3. Set the Endpoint URL to your Jira Cloud REST API endpoint: https://<your-domain>.atlassian.net/rest/api/2/issue. Replace <your-domain> with your Jira Cloud domain (e.g., acme if your Jira URL is acme.atlassian.net).

  4. Review the transformation code automatically generated for Jira issues. You can customize this transformation at any time. Learn more about customizing transformations.

  5. Create the new endpoint. You will be redirected to the endpoint configuration view.

If you're having trouble adding a new webhook endpoint with Svix, please see the Adding Endpoint docs from Svixarrow-up-right.

3. Add custom headers

The Jira REST API requires authentication headers. You can configure custom headers in the endpoint configuration:

  1. Navigate to Webhooks > Advanced > Custom Headers.

  2. Fill in the Key and Value referencing the table below, and click the + button to add each header.

You'll need to configure the following headers:

Key
Value

Authorization

Basic <BASE64_TOKEN>

Content-Type

application/json

Replace <BASE64_TOKEN> with the Base64-encoded string you generated in step 1.

4. Find your Jira project key and issue type

You'll need your Jira project key and preferred issue type to configure the transformation.

Project key: This is the short prefix on your Jira issues (e.g., ENG, PROJ, KAN). You can find it in the URL when viewing your Jira project: https://your-domain.atlassian.net/jira/software/projects/<PROJECT_KEY>/board.

Issue type: The type of issue to create. Common values are Bug, Task, or Story. The default is Bug.

5. Customize your transformation

Transformations are custom code snippets you can write to customize the Jira issues created by the webhook. A working template transformation will be added automatically for your webhook, but you can further customize the behavior.

  1. In the endpoint configuration view, navigate to the Advanced tab. Under Transformation, toggle the Enabled switch.

  2. Click Edit transformation to update your transformation code, and click Save to update the transformation.

  3. You can test the transformation by selecting the test_case.status_changed payload and clicking Run Test. This will test the transformation but not send a message. You will learn to send a test message in step 6.

The generated webhook template contains several configurable constants out of the box:

Constant
Description

JIRA_PROJECT_KEY

(Required) Your Jira project key (e.g., ENG, PROJ).

JIRA_ISSUE_TYPE

(Optional) The issue type to create. Defaults to Bug.

JIRA_LABELS

(Optional) Array of labels to add to the issue. Defaults to ["flaky-test"].

JIRA_CUSTOM_FIELDS

(Optional) Object of custom field key-value pairs for projects that require additional fields.

PRS_IMPACTED_THRESHOLD

Issues will be created only for flaky tests that have impacted more PRs than the PRS_IMPACTED_THRESHOLD. You can adjust this value if you see many issues about low-impact flaky tests.

Here is the provided transformation for context. You can customize your Jira issues integration by following the Jira REST API docsarrow-up-right and Svix transformationsarrow-up-right documentation.

circle-info

The default transformation only creates issues when newStatus === "flaky". If you also want to create issues for tests marked as Broken (consistently failing at a high rate), update the filter condition. For example, change newStatus !== "flaky" to newStatus !== "flaky" && newStatus !== "broken" to handle both statuses.

circle-info

The description uses Jira wiki markuparrow-up-right for formatting. Links use the [text|url] syntax rather than markdown.

6. Test your webhook

You can create test issues by delivering a mock webhook. You can do this by:

  1. In the endpoint configuration view, navigate to the Testing tab and select a Send event

  2. Under Subscribed events, select test_case.status_changed as the event type to send

  3. Click Send Example to test your webhook

7. Monitoring webhooks

You can monitor the events and the webhook's delivery logs in the Overview tab of an endpoint configuration view.

You can see an overview of how many webhook deliveries have been attempted, how many are successful, how many are in flight, and how many fail in the Attempt Delivery Status modal.

You can see a list of past delivery attempts in the Message Attempts modal. You can filter this list by Succeeded and Failed status, and you can click on each message to see the Message content, response code, and error message of each attempt. You can learn more about replaying messagesarrow-up-right and filtering logsarrow-up-right in the Svix docs.

Congratulations!

A Jira issue will now be created when a test's health status changes to flaky and impacts more than 2 PRs. You can further modify your transformation script to customize your issues.

See the Trunk webhook event catalogarrow-up-right

Learn more about consuming webhooks in the Svix docsarrow-up-right

Learn more about Jira's REST APIarrow-up-right

Last updated

Was this helpful?