# Pipeline Integration

Learn how to integrate Unit Tests with Buddy pipelines using the Collect tests results feature.

After creating a test suite, you can use it in a pipeline.

## Pipeline configuration

1. Add a Build action (e.g., Node) to your pipeline
2. In the **commands** section, on the right side, you'll find the **Collect test** results button
3. Click **Collect test results** to open the configuration.

![Pipeline Action - Collect Tests Results](/docs/tests/unit-tests/unit-tests-pipeline-1.png 640x400)

## Framework and suite selection
In the popup: 

- Select the created Suite from the dropdown list
- Choose the Framework instruction (e.g., Jest, Playwright, Cypress)
- Follow the provided instructions

![Collect Tests Results Configuration](/docs/tests/unit-tests/unit-tests-pipeline-2.png 640x500)

## Finalizing configuration

1. Click **Set configuration** - the selected Suite will appear in the **Collect test results** button.
2. Add the commands in the **commands** section according to the instructions displayed in the popup.

![Pipeline Action with Configured Test Suite](/docs/tests/unit-tests/unit-tests-pipeline-3.png 640x400)

After running the pipeline, the tests will be executed, and the results will be visible in the **Unit Tests** section in the project sidebar, where you can select your Suite. You can also access them directly from the execution summary.

![Unit Tests in run view](/docs/tests/unit-tests/unittest-execution.png 640x611)

<Hint type="info">
You don’t need to manually set the `BUDDY_UT_TOKEN` environment variable in the pipeline - Buddy automatically uses the token assigned to the selected Suite.
</Hint>

You can find detailed information about viewing test results in the [Results & Analytics](/docs/tests/unit-tests/results-and-analytics.md) section.

## Triggering pipelines on test results

A finished test session can start another pipeline. Add the **Unit Tests: Session ended** trigger to the pipeline that should react and filter it by suite, branch, and session status - for example, deploy only when the suite passed, or notify the team when it failed.

1. Open the pipeline and go to the **Workflow** tab.
2. Click **+** in the **Triggers** section and select **Session ended** in the **Unit Tests** group.
3. Pick the **Suite**, **Branch**, and **Session statuses** and click **Apply changes**.

The same trigger in YAML. The `suites` list takes suite **IDs** (shown next to the name in the suite's settings), not display names:

```yaml
- pipeline: "Deploy to production"
  refs:
    - "refs/heads/master"
  events:
    - type: "UT_SESSION_ENDED"
      branches:
        - "master"
      suites:
        - "api_tests"
      statuses:
        - "SUCCESSFUL"
```

The trigger reacts to the session, not to the pipeline that ran the tests, so it also works for results sent from GitHub Actions or uploaded with the CLI. See [On unit test event](/docs/pipelines/introduction/triggering-pipelines/on-unit-test-event.md) for all filter options.


---
Original source: https://buddy.works/docs/tests/unit-tests/pipeline-integration