---
title: Ginkgo Integration with Mergify
description: Report your test results from Ginkgo to Mergify
---

This guide shows how to generate a JUnit report from your
[Ginkgo](https://onsi.github.io/ginkgo/) specs and upload it to
**Test Engine** from your CI workflow.

For tests written with Go's `testing` package alone, see the
[Go guide](/test-engine/test-frameworks/golang).

## Generate a JUnit report with Ginkgo

The `ginkgo` command writes a JUnit report when you pass `--junit-report`:

```bash
ginkgo -r --keep-going --junit-report=junit.xml
```

`-r` runs every suite under the current directory, and Ginkgo merges their
results into one `junit.xml` at the root. Do not drop `--keep-going`: without
it, Ginkgo stops after the first suite that fails, and the suites it did not
run are missing from the report.

## Update your CI workflow

### GitHub Actions

Run the specs in a step with an `id`, and let the upload step decide the
job's result:

```yaml
- name: Install Ginkgo
  run: go install github.com/onsi/ginkgo/v2/ginkgo

- name: Run Ginkgo Specs
  id: tests
  continue-on-error: true
  run: ginkgo -r --keep-going --junit-report=junit.xml
```

Installing `ginkgo` from your module, as above, keeps the command at the
version of Ginkgo your `go.mod` requires.

```yaml
- name: Mergify Test Engine Upload
  if: (success() || failure()) && (!github.event.pull_request || github.event.pull_request.head.repo.full_name == github.repository)
  uses: mergifyio/gha-mergify-ci@v35
  with:
    report_path: junit.xml
    test_step_outcome: ${{ steps.tests.outcome }}
```

Key points:

- `if: (success() || failure()) && (!github.event.pull_request || github.event.pull_request.head.repo.full_name == github.repository)`: runs the upload step even when the tests fail, so **Test Engine** gets the full report, and skips it on pull requests from forks, which get no ID token.
- `report_path: junit.xml`: where your test run writes the JUnit file. It must match the path your test configuration uses.
- `test_step_outcome: ${{ steps.tests.outcome }}`: passes the test step's outcome, so Mergify detects a runner that crashed while the JUnit report looks clean. Give your test step an `id` (here `tests`) and use it in `steps.<id>.outcome`.

If you use a job matrix in your workflow (e.g., to test across multiple versions), every leg reports the same job name, because GitHub Actions gives them all one `GITHUB_JOB`. Set the `job_name` input so **Test Engine** can tell the reports apart:

```yaml
jobs:
  example_matrix:
    strategy:
      matrix:
        version: [10, 12, 14]
```

Your upload step should look like:

```yaml
- name: Mergify Test Engine Upload
  if: (success() || failure()) && (!github.event.pull_request || github.event.pull_request.head.repo.full_name == github.repository)
  uses: mergifyio/gha-mergify-ci@v35
  with:
    job_name: example_matrix (${{ matrix.version }})
    report_path: junit.xml
    test_step_outcome: ${{ steps.tests.outcome }}
```

> **Note:** the job name is part of a test's identity, so a scheduled workflow has to report the same name as the job running those tests on your pull requests.

To benefit from Test Engine quarantine, you need to add `continue-on-error: true`
in your GitHub Actions step that executes your tests and generates the JUnit file.
The step running the `gha-mergify-ci` action then decides whether the job passes or fails,
taking quarantined tests into account.

With `continue-on-error: true`, the job's result comes from the upload step,
which pull requests from forks skip: add the step that fails the job when the
tests failed and nothing was uploaded, as shown in
[pull requests from forks](/ci-insights/setup/github-actions#pull-requests-from-forks).

#### Let your CI reach Mergify

Grant `id-token: write` to the job, or to the whole workflow. The job then trades its GitHub-signed ID token for a Mergify OIDC CI token, and no `MERGIFY_TOKEN` is stored:

```yaml
permissions:
  id-token: write # lets the job ask GitHub for an ID token
  contents: read # actions/checkout needs it
```

A `permissions` block sets every permission it does not list to `none`: list the ones your other steps need too.

Mergify refuses the ID token until a trust policy of your organization matches the job. A GitHub organization `Owner` or a **CI Admin** writes one under **Settings → Security & Access → CI Authentication → Trust Policies** on the [dashboard](https://dashboard.mergify.com). [OIDC Authentication](/integrations/gha/oidc) covers trust policies, pull requests from forks and refused exchanges. If your workflows store `MERGIFY_TOKEN` today, [move them off it](/integrations/gha/oidc#move-your-workflows-off-mergify_token).

#### Use an application key instead

Other CIs authenticate with a `ci` [application key](/api/application-keys#ci-reporting), and so do the GitHub Actions jobs OIDC leaves out: runs for pull requests from forks when your organization sends them secrets, and jobs that send scopes from the base branch (`pull_request_target`, `workflow_run`, `issue_comment`). Store the key as the `MERGIFY_TOKEN` repository secret and set it on the job:

```yaml
env:
  MERGIFY_TOKEN: ${{ secrets.MERGIFY_TOKEN }}
```

A `MERGIFY_TOKEN` that is set wins over the ID token. For pull requests from forks, set it on those runs only and drop the fork condition from the upload step, as [Jobs that keep a key](/integrations/gha/oidc#jobs-that-keep-a-key) shows. Store the key in your [Dependabot secrets](/integrations/dependabot#reaching-mergify-from-dependabot-pull-requests) too, since runs for Dependabot pull requests read only those.

### Buildkite

```yaml
steps:
  - label: "Run tests"
    command: <your test command>
    plugins:
      - mergifyio/mergify-ci#v30:
          action: junit-process
          report_path: junit.xml
```

Key points:

- The plugin runs in the `post-command` hook, so it uploads results **after** your tests finish, even if they fail.
- `report_path: junit.xml`: where your test run writes the JUnit file. It must match the path your test configuration uses.
- Silent failure detection is automatic: the plugin reads the step's exit code to detect a runner that crashed while the JUnit report looks clean.

If you use a build matrix in your pipeline, each variation reports its own step label as its job name, so the variations are already distinct. Set the `job_name` plugin property when the label is not the name you want **Test Engine** to file the reports under:

```yaml
steps:
  - label: "Flaky detection ({{matrix}})"
    matrix:
      - "3.10"
      - "3.11"
      - "3.12"
    command: <your test command>
    plugins:
      - mergifyio/mergify-ci#v30:
          action: junit-process
          job_name: "Tests ({{matrix}})"
          report_path: junit.xml
```

> **Note:** the job name is part of a test's identity, so a scheduled pipeline has to report the same name as the step running those tests on your pull requests.

> **Caution: keep the token out of the pipeline you upload.** Set `MERGIFY_TOKEN` in the environment of the agents running your steps: [Buildkite secrets](https://buildkite.com/docs/pipelines/security/secrets/buildkite-secrets), a secrets plugin backed by your own secrets store, or an agent `environment` hook that exports it. Do not put the token in the pipeline itself: `buildkite-agent pipeline upload` interpolates `${MERGIFY_TOKEN}` before the pipeline is stored, so a token written into an `env:` block is uploaded in plain text and stays readable in the Buildkite UI and in build history. The plugin's `token:` property carries it the same way.

When using the Buildkite plugin for Test Engine quarantine, the plugin automatically
detects test failures using the step's exit code. No extra configuration is needed.

The `mergifyio/mergify-ci` plugin runs in the `post-command` hook and reads
`BUILDKITE_COMMAND_EXIT_STATUS` to detect silent failures where the test runner
crashed but the JUnit report appears clean.

### Any CI (Mergify CLI)

Install the [Mergify CLI](/cli/usage) in your pipeline and export `MERGIFY_TOKEN`. Run `mergify ci junit-process` after your tests:

```bash
set -o pipefail
exit_code=0
ginkgo -r --keep-going --junit-report=junit.xml || exit_code=$?
mergify ci junit-process \
  --test-exit-code "$exit_code" \
  junit.xml
```

Key points:

- `MERGIFY_TOKEN`: export this environment variable with your Mergify application key so `junit-process` can authenticate to the API. On GitHub Actions, a job granted `id-token: write` needs none: it trades its ID token for a Mergify OIDC CI token, as [OIDC Authentication](/integrations/gha/oidc) explains.
- `|| exit_code=$?`: CI shells run with `-e`, so a failing test command on its own line would end the script before the upload. This form keeps going and records the code.
- The script needs bash for `set -o pipefail`: on Jenkins, whose `sh` steps often run `dash`, start it with `#!/bin/bash`.
- `--test-exit-code "$exit_code"`: passes the test runner's exit code, so Mergify detects a runner that crashed while the JUnit report looks clean.
- `junit-process` runs last, so its status becomes the step's: `0` when every failure it found is quarantined, `1` when one is not.
- The branch quarantine is evaluated against is detected from your CI provider, falling back to the checked-out branch. Pass `--tests-target-branch <branch>` only to override it.

## Test names

Test Engine names each spec by its suite's description, the one you pass to
`RunSpecs`, then a dot and the spec's full text: its kind in brackets, then the
texts of the containers around it and its own, joined with spaces. The spec
`It("adds an item")` inside `Describe("Add")` inside `Describe("Cart")`, in a
suite started with `RunSpecs(t, "Cart Suite")`, is reported as
`Cart Suite.[It] Cart Add adds an item`.

Give each suite a distinct description, so specs of the same text in two
packages keep separate histories. Renaming a suite, a container or a spec
starts a new history for the specs it holds.

The spec's labels are part of its name: `It("ships", Label("slow"))` inside
`Describe("Order")`, in the suite `Order Suite`, is reported as
`Order Suite.[It] Order ships [slow]`, so adding or removing a label also
starts a new history. Each `Entry` of a `DescribeTable` is a spec of its own,
named after the entry's description.

Specs marked pending, such as `PIt`, and specs that call `Skip()` are reported
as skipped.

## Verify and review in Test Engine

After pushing these changes:

1. Your CI workflow runs your Ginkgo specs.
2. Ginkgo writes `junit.xml`.
3. Mergify uploads the report to Test Engine.

You can then review your test results, including any failures or flaky tests,
directly in the [Test Engine
dashboard](https://dashboard.mergify.com/test-engine/detection).

## Troubleshooting tips

<ul>
  <li>Suites missing from the report: add `--keep-going`, so Ginkgo runs every suite after one fails.</li>

  <li>The CLI provides information about the upload. Check the logs in GitHub Actions.</li>
<li>File paths: Double-check that the output file matches the path used in `report_path`.</li>
<li>
  Authentication: The upload step's log says why Mergify refused the job's ID token, as [OIDC
  troubleshooting](/integrations/gha/oidc#troubleshooting) details. A job that sets
  `MERGIFY_TOKEN` uses that key instead: check that it is valid and granted [CI
  Reporting](/api/application-keys#ci-reporting), or [move the job off
  it](/integrations/gha/oidc#move-your-workflows-off-mergify_token).
</li>
<li>Workflow conditions: If your step is not running, confirm the if condition is actually triggered in your job.</li>
</ul>
