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.
Click Create API token, give it a label (e.g., "Trunk Webhooks"), and click Create.
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" | base64Replace [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:
Login to Trunk Flaky Tests
From your profile on the top right, navigate to Settings
Under Organization > Webhooks, click Automate Jira Issues Creation.
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.,acmeif your Jira URL isacme.atlassian.net).Review the transformation code automatically generated for Jira issues. You can customize this transformation at any time. Learn more about customizing transformations.
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 Svix.
3. Add custom headers
The Jira REST API requires authentication headers. You can configure custom headers in the endpoint configuration:
Navigate to Webhooks > Advanced > Custom Headers.
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:
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.
In the endpoint configuration view, navigate to the Advanced tab. Under Transformation, toggle the Enabled switch.
Click Edit transformation to update your transformation code, and click Save to update the transformation.
You can test the transformation by selecting the
test_case.status_changedpayload 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:
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 docs and Svix transformations documentation.
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.
The description uses Jira wiki markup 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:
In the endpoint configuration view, navigate to the Testing tab and select a Send event
Under Subscribed events, select
test_case.status_changedas the event type to sendClick 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 messages and filtering logs 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 catalog
Last updated
Was this helpful?

