GitLab CI Coverage Not Parsed - "coverage" Regex Does Not Match
GitLab reads a coverage percentage by matching a regex against the job’s log output. If the regex does not match what the tool prints, coverage shows as "unknown" and MR coverage is empty.
What this error means
Tests run and print coverage, but the pipeline/badge shows no coverage value and MRs report nothing. The coverage: regex and the actual tool output do not line up.
# Tool prints: "TOTAL 1234 99 92%"
test:
coverage: '/^TOTAL.+?(\d+\%)$/' # anchored regex misses the real line formatCommon causes
Regex does not match the printed line
The coverage: regex must match the exact line the tool emits. Anchors, spacing, or a missing capture group around the percentage cause it to never match.
Coverage output suppressed or summarized elsewhere
If the coverage summary is written to a file but not stdout, there is nothing in the log for the regex to match.
How to fix it
Match the tool’s actual output
Print the coverage summary to the log and write a regex with a capture group around the percentage.
test:
script:
- pytest --cov=app --cov-report=term
coverage: '/TOTAL\s+\d+\s+\d+\s+(\d+%)/'Ensure coverage reaches stdout
- Confirm the coverage summary prints in the job log, not only to a file.
- Copy the exact summary line and build the regex from it.
- Test the regex against the line before relying on it.
How to prevent it
- Keep the
coverage:regex in sync with the test tool’s output format. - Always print a coverage summary line to stdout.
- Prefer coverage report artifacts (Cobertura) for richer MR coverage where supported.