How to Show Coverage in GitLab CI
GitLab reads the coverage percentage from a regex on the job log and the diff view from a Cobertura report.
Set a coverage: regex on the job so GitLab parses the total from the log, and add a coverage_report artifact of type cobertura so covered lines show in the merge request diff.
.gitlab-ci.yml
.gitlab-ci.yml
test:
script:
- pytest --cov=myapp --cov-report=term --cov-report=xml
coverage: '/^TOTAL.+?(\d+\.\d+\%)$/'
artifacts:
reports:
coverage_report:
coverage_format: cobertura
path: coverage.xmlGotchas
- The
coverage:regex must capture exactly one group, and it runs against the job log, not the report file. - The Cobertura artifact drives the per-line diff view; without it you get the percentage but no inline highlighting.
Related guides
How to Convert Between lcov, Cobertura, and coverage.xml in CIUnderstand and convert the common coverage report formats in CI (lcov.info, Cobertura XML, coverage.xml) so a…
How to Generate pytest Coverage in CIMeasure Python test coverage in CI with pytest-cov, running pytest --cov to print a report and emit coverage.…
How to Enforce Coverage on the Diff Only in CIRequire coverage only on changed lines in CI using Codecov patch status, so new code is tested without demand…