CI & sharding
There is no Piwi-specific step to add to CI: the reporter runs inside npx playwright test and pushes results as they happen. You set two environment variables.
env:
PIWI_DASHBOARD_URL: https://piwi.example.com
PIWI_API_KEY: ${{ secrets.PIWI_API_KEY }} # only if authentication is enabledWith authentication off, the server's PIWI_SITE_URL or PIWI_ALLOWED_HOSTS must name the domain or container name in that URL (why).
Everything else — branch, commit, author, workflow, build URL, shard index — is detected automatically.
A serverUrl written in the Playwright config wins over PIWI_DASHBOARD_URL. init writes it as process.env.PIWI_DASHBOARD_URL || '<the URL you gave>', so the variable takes over in CI; a config that names the URL alone keeps sending to that URL.
GitHub Actions
name: e2e
on: [push]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- run: npm ci
- run: npx playwright install --with-deps
- run: npx playwright test
env:
PIWI_DASHBOARD_URL: https://piwi.example.com
PIWI_API_KEY: ${{ secrets.PIWI_API_KEY }}Piwi keeps every result, so the job's output can hold the failures alone: Playwright 1.65's failures reporter prints only them, and onlyFailures: true keeps an html, json or junit report to them (wrapConfig adds Piwi):
reporter: process.env.CI ? [['failures'], ['junit', { outputFile: 'junit.xml', onlyFailures: true }]] : 'list',The shallow clone actions/checkout makes is enough for the reporter: Piwi reads diffs from your Git host's API (Source control). run impact --base and preflight --base diff the checkout itself and need the base commit: set fetch-depth: 0 on actions/checkout.
GitLab CI
e2e:
image: mcr.microsoft.com/playwright:v1.65.1-noble # the version of your @playwright/test
script:
- npm ci
- npx playwright test
variables:
PIWI_DASHBOARD_URL: https://piwi.example.com
PIWI_API_KEY: $PIWI_API_KEYOther systems
Jenkins, CircleCI, Azure DevOps, Travis, Buildkite, TeamCity, Bitbucket, Semaphore, AppVeyor and Drone are recognized too; set the same two variables. An unrecognized CI means less auto-filled metadata.
What gets detected
Unconfigured, the reporter records:
- Source control: commit SHA, message, author, branch, pull-request number, the pull request's target branch, and the repository URL. On a pull-request build the target branch is recorded as the run's base branch, which baselines fall back to when the branch has no history of its own.
- CI: provider, workflow or job name, build number, and a link back to the CI build.
- Origin: what launched it.
- Environment: Playwright version, browser and viewport, run environment.
- Shard index: from Playwright's own
--shardconfig.
Test metadata lists the variables each field comes from. PIWI_BRANCH and PIWI_BASE_BRANCH override the resolved branches; collectScmInfo: false or collectCiInfo: false turns a collector off.
Sharding
Playwright's --shard=1/3 splits a suite across parallel jobs. Piwi merges them back into one run.
strategy:
matrix:
shard: [1, 2, 3]
steps:
- run: npx playwright test --shard=${{ matrix.shard }}/3
env:
PIWI_DASHBOARD_URL: https://piwi.example.com
PIWI_API_KEY: ${{ secrets.PIWI_API_KEY }}How the merge works:
- Each shard derives a run label, a stable identifier for the CI pipeline, from the provider's build id (
GITHUB_RUN_IDwithGITHUB_RUN_ATTEMPT,CI_PIPELINE_ID,CIRCLE_WORKFLOW_IDand their equivalents on the systems listed above). A re-run of a GitHub Actions workflow is a new attempt, so it starts a new run. - Shards sharing a run label, a
projectNameand a shard count (the3of--shard=1/3) resolve to the same run, streamed or batched. - The run stays
runninguntil the last shard reports. While none of its shards is running, it waits up to an hour for the next one, streamed or batched, so a shard may start an hour after the others ended. It also waits up to an hour for a shard still in its global setup. - Counters accumulate across shards, and the run page shows a shard progress badge (
2/3) while shards are arriving. A shard counts once, even when it reports its end twice (its/finishanswer lost, then its batch upload). The run takes the most severe status its shards reported, as Playwright'smerge-reportsdoes:failed, thentimedout, theninterrupted. It isfailedwhenever a test failed. - The run lasts from the first shard's start to the last shard's end, whether the shards run side by side or one after another. Its metadata keeps each shard's start, end, worker count and status under
shards.
All shards must use the same projectName.
Playwright counts a sharded run's tests before it splits them, so a shard left with none passes. From Playwright 1.65, a sharded run fails with No tests found when its whole selection is empty, as an unsharded one does, unless it passes --pass-with-no-tests: piwi run --plan passes it to every shard.
Jobs sharded with piwi run --shard, or balanced by duration, merge the same way.
If your CI isn't detected, set the label yourself to anything common to all shards:
['@piwitests/reporter', {
serverUrl: 'https://piwi.example.com',
projectName: 'my-project',
runLabel: process.env.BUILD_TAG || 'my-custom-label',
}]Parallel jobs in one pipeline
A job that is not sharded adds the CI job's id (GITHUB_JOB, CI_JOB_ID, …) to its run label, so a GitLab e2e:chrome and e2e:firefox reporting to one projectName stay two runs. The legs of a GitHub Actions matrix share one job id, and Jenkins, TeamCity and Drone expose none: give each leg its own label, or its own projectName. On GitHub Actions, strategy.job-index numbers the jobs of a matrix, whatever its keys:
PIWI_RUN_LABEL: ${{ github.run_id }}-${{ github.run_attempt }}-${{ strategy.job-index }}A configured label is used as it is, so each job of the matrix gets a run of its own, a shard too. When the legs are themselves sharded (shard: [1, 2, 3] beside browser), put the leg's keys in the label instead (matrix.browser): the shards of a leg share them, and merge into one run. Two matrix jobs of one workflow that report to one projectName also need github.job in the label, since each numbers its jobs from 0.
Jobs left sharing a label cancel each other's live runs: the reporter of a cancelled run stops streaming and sends its results in one batch at the end of its job, so each job still ends in one complete run, without its live progress.
Watching a run while CI is still going
Streaming is on by default: the run fills in test by test, so a failure's trace is readable before the pipeline ends (Live streaming).
Getting the run URL back out of CI
Later pipeline steps can pick up the run URL. Every channel is best-effort: a failure is logged, never fatal.
Always — one line per failed test, printed the moment its final attempt fails, then a View run: <url> line once the run lands:
[Piwi Dashboard] ✗ applies the discount code — getByRole('button', { name: 'Pay' }) never became enabled — click timed out after 30 s → https://piwi.example.com/test-runs/42/locate?file=tests%2Fcheckout.spec.ts&title=applies%20the%20discount%20code&retry=1&browser=chromium
[Piwi Dashboard] View run: https://piwi.example.com/test-runs/42Between the title and the link is the failure's one-line headline. The per-test link opens the failing execution's page, even while the run is still going.
GitHub Actions (automatic) — a ::notice:: titled Piwi live run as the run starts, so the job's log links the run while it runs; then step outputs, a job summary listing the failed tests with their links (20 at most, the rest counted as "+N more"), and a ::notice:: annotation titled Piwi test run:
- run: npx playwright test
id: e2e
env:
PIWI_DASHBOARD_URL: https://piwi.example.com
- run: echo "Results: ${{ steps.e2e.outputs.piwi_run_url }}"
if: always()Available outputs: piwi_run_url, piwi_run_id, piwi_run_status, piwi_failed_count, piwi_project_id.
GitLab CI (automatic) — a dotenv report (piwi.env by default, override with PIWI_DOTENV_FILE) carrying PIWI_RUN_URL, PIWI_RUN_ID, PIWI_RUN_STATUS, PIWI_FAILED_COUNT, PIWI_PROJECT_ID and PIWI_CI_BUILD_URL. Declare it so later jobs inherit the variables:
e2e:
script:
- npx playwright test
artifacts:
reports:
dotenv: piwi.envAny other system — set outputFile (or PIWI_OUTPUT_FILE) and read the JSON:
- run: npx playwright test
env:
PIWI_OUTPUT_FILE: piwi-run.json
- run: cat piwi-run.json # { runUrl, runId, projectId, projectName, status, ciBuildUrl, failedCount, failures }failures lists every test whose final attempt failed as { title, file, retry, browser, repeatEachIndex, headline, url }, with url the per-test link the log prints.
Pull-request feedback
Piwi can post a summary comment and a commit status on the pull request: see Pull-request feedback. To re-run a failure cluster's tests in CI, see Re-run in CI.
Blocking a merge
npx playwright test exits non-zero when anything failed. Did this change break something that was working needs the run history, so the dashboard evaluates it: the CI merge gate says what fails it, what only warns and what it leaves out.
- run: npx playwright test
env:
PIWI_DASHBOARD_URL: https://piwi.example.com
PIWI_OUTPUT_FILE: piwi-run.json # records which run to gate on
- run: npx @piwitests/reporter gate --require-tag @critical --max-new-regressions 0
if: always()
env:
PIWI_DASHBOARD_URL: https://piwi.example.com
PIWI_API_KEY: ${{ secrets.PIWI_API_KEY }}The command reads the run id from PIWI_OUTPUT_FILE (or --run-id, or ./piwi-run.json) and prints each violation.
A failed gate exits 1 and prints:
✖ Piwi gate failed — checkout run #412
248 tests, 3 failed, 1 new, 0 newly flaky, 2 flaky
1 failing test is quarantined and did not count
✖ 1 required @critical test failed: pays by card
✖ 1 new regression (limit 0)
https://piwi.example.com/test-runs/412Every flag and exit code is in the CLI reference; --json prints the raw result for a pipeline to parse.
Notifying people instead
To tell the team when main goes red, use a notification subscription, whose rules live in one place.
Troubleshooting
Results don't appear. Check the CI log for the reporter's own output; run with PIWI_VERBOSE=true for the full request trace. The usual causes are a PIWI_DASHBOARD_URL the runner cannot reach, or a missing API key while authentication is on.
Shards create several runs instead of one. The run label wasn't detected, or the shards disagree on projectName or the shard count. Set runLabel explicitly.
Traces or screenshots are missing. Playwright records neither by default, so there is nothing to upload. Set use: { trace: 'retain-on-failure', screenshot: 'only-on-failure' } in your Playwright config, or install through wrapConfig, which sets both when they are unset.
A run is stuck as interrupted. A run silent for two minutes (a cancelled job, a killed runner, a dropped network) is marked interrupted until its next event revives it. A run still in its global setup (initializing), or a sharded run with a shard still in its own, waits an hour for its reporter to begin it. A run still uploading its files or its reports (finalizing) waits ten minutes after the last one arrived, then keeps the status the reporter sent. Analytics counts interrupted runs as failing; full runs only drops only partial runs.
Related
- Reporter: setup, streaming and authentication
- Pull-request feedback: the result on the pull request
- CI merge gate: what the gate decides
- Test tags: what
--require-tagmatches on - API keys: the key CI uses