Test Engine Setup – CircleCI
Send test results from CircleCI to Mergify Test Engine.
CircleCI jobs can send their test results to Test Engine. Mergify does not collect CircleCI job runs for CI Insights’ job views: only test results reach it, through the test plugins or a JUnit report.
Before You Start
Section titled Before You Start-
Enable CI Insights for the repository on the Repositories page of the dashboard (docs). Without it, uploads are refused.
-
Create a Mergify application key with the
ciscope, as described in the API Usage documentation. -
Store it as
MERGIFY_TOKENin CircleCI, never in.circleci/config.yml:-
Project environment variable: Project Settings → Environment Variables (
https://app.circleci.com/settings/project/github/<owner>/<repository>/environment-variables). Every job of the project receives it; nothing changes in the configuration. -
Or a context, to share one key across projects: Organization Settings → Contexts. Jobs receive a context only when the workflow names it, so add
context: [<your context>]to each test job underworkflows.
-
CircleCI publishes no base branch for a pull request build, so Test Engine reads pull request builds like branch builds: Prevention, which works on pull requests, does not apply.
CircleCI does not pass project environment variables or contexts to builds of
pull requests from forks unless the project setting Pass secrets to builds
from forked pull requests is on. Those builds run without MERGIFY_TOKEN.
With a Test Plugin
Section titled With a Test PluginFor pytest,
RSpec,
Vitest,
Playwright,
Jest and
Mocha, install the plugin as its page
describes. No step changes: CircleCI sets CI and the CIRCLE_*
variables the plugin reads, and the job receives MERGIFY_TOKEN from the
project or the context.
-
Job names: each job reports under its name (
CIRCLE_JOB). The legs of amatrixget their expanded names (such astest-3.12), so they are already distinct. Parallel containers of one job (parallelism) share the name, which is right: they run parts of the same suite. -
Tests inside Docker: the
dockerexecutor already runs your steps in the container, and the variables reach them. When a step starts the tests itself withdocker runor Docker Compose, passMERGIFY_TOKEN,CI,CIRCLECIandCIRCLE_*through to that container. -
Without a token (fork builds), the plugins upload nothing and your tests run as usual.
With a JUnit Report
Section titled With a JUnit ReportFor any other framework, write a JUnit XML report from your test run, install the Mergify CLI in the job, and upload the report in the step that runs the tests:
Install the Mergify CLI in your pipeline and export
MERGIFY_TOKEN. Run
mergify ci junit-process after your tests:
set -o pipefailexit_code=0<your test command> || exit_code=$?mergify ci junit-process \ --test-exit-code "$exit_code" \ junit.xmlKey Points:
-
MERGIFY_TOKEN: Export this environment variable with your Mergify application key sojunit-processcan authenticate to the API. -
|| 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 forset -o pipefail: on Jenkins, whoseshsteps often rundash, start it with#!/bin/bash. -
--test-exit-code "$exit_code": Passes the test runner's exit code so Mergify can detect silent failures where the runner crashed but the JUnit report appears clean. -
junit-processexits last, so its status becomes the step's. Quarantine depends on that: it exits0when every failure it found is quarantined, and1when one is not. Re-exiting with the test runner's own code would fail the step whatever quarantine decided. -
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.
CircleCI runs each step with bash -eo pipefail: keep the test command and the
upload in the same run step, as above, so the upload happens even when tests
fail. On a fork build, junit-process has no token and fails the step: skip it
when MERGIFY_TOKEN is empty, for example
if [ -n "${MERGIFY_TOKEN:-}" ]; then mergify ci junit-process …; else exit "$exit_code"; fi.
Was this page helpful?
Thanks for your feedback!