# Linear integration

When Trunk Flaky Tests [detects a flaky test](https://docs.trunk.io/flaky-tests/detection), you can create an automatically generated Linear ticket for your team to pick up and fix the test.

Webhook payloads will also contain ticket information when a Jira ticket is created with the integration or when [existing tickets are linked](#link-existing-tickets-to-tests).

### Connecting to Linear

<figure><picture><source srcset="https://577236045-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F61Ep9MrYBkJa0Yq3zS1s%2Fuploads%2Fgit-blob-41813a6f39352ad1f8aacabc083bc1e4f3680068%2Flinear-integration-dark.png?alt=media" media="(prefers-color-scheme: dark)"><img src="https://577236045-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F61Ep9MrYBkJa0Yq3zS1s%2Fuploads%2Fgit-blob-5b4191fbefa72ca275113c15f3dd079e89211bd1%2Flinear-integration-light.png?alt=media" alt=""></picture><figcaption></figcaption></figure>

To connect a Linear project:

1. Navigate to **Settings** > **Repositories** > **Ticketing Integration.**
2. Select **Linear** as your Ticketing System.
3. Add a [Linear API key](#api-token-permissions)
4. Select a Team and **Connect to Linear**.

After connecting to Linear, you can specify a default project and a default assignee for new tickets.

#### API Key permissions

The following project permissions must be granted to your Linear API key so Trunk can read, create, and assign tickets automatically:

* *Read*
* *Create issues*

Selecting *Full Access* will also grant the required permissions.

### Create a new ticket

You can create a new ticket for any test listed in Flaky Tests.

There are 2 ways to create a new ticket in the Flaky Tests dashboard:

* Click on the options menu for any test case on the repo overview dashboard

<figure><picture><source srcset="https://577236045-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F61Ep9MrYBkJa0Yq3zS1s%2Fuploads%2Fgit-blob-ed8cc1cf189c6d04566b5c6fa9aacc492af80cfd%2Fcreate-ticket-button-dark.png?alt=media" media="(prefers-color-scheme: dark)"><img src="https://577236045-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F61Ep9MrYBkJa0Yq3zS1s%2Fuploads%2Fgit-blob-7eb96ca61d9f68735894421fa4541def8a4d5835%2Fcreate-ticket-button-light.png?alt=media" alt=""></picture><figcaption></figcaption></figure>

* Use the Create ticket button in the top left corner of the [test case details](https://docs.trunk.io/dashboard#test-case-details) page.

Before you create the ticket, you get a preview of the title and description.

<figure><picture><source srcset="https://577236045-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F61Ep9MrYBkJa0Yq3zS1s%2Fuploads%2Fgit-blob-0adeb36dec5ce71d5d7ad304fdc0979bb0a18626%2Fjira-ticket-creation-dark.png?alt=media" media="(prefers-color-scheme: dark)"><img src="https://577236045-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F61Ep9MrYBkJa0Yq3zS1s%2Fuploads%2Fgit-blob-429369987aa4c1d55aabdb5e1b4ebf7f4e4c2325%2Fjira-ticket-creation-light.png?alt=media" alt=""></picture><figcaption></figcaption></figure>

#### Create with Linear

If you are connected to Linear, you can click the **Create Linear Ticket** button at the end of the modal to automatically create a ticket with the configured team and assignees.

Note: You can use [Flaky Tests webhooks](https://docs.trunk.io/flaky-tests/webhooks/linear-integration) to automate ticket creation, or if you need more control over how tickets are created in Linear. This integration is not required when using webhooks.

#### Link existing tickets to tests

If you already have a ticket in Linear that you want to link to a test in the dashboard, you can use the [Link Ticket to Test Case API](https://docs.trunk.io/flaky-tests#post-flaky-tests-link-ticket-to-test-case).
