Skip to content
Latchkey

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.xml

Gotchas

  • 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

Run this faster and cheaper on Latchkey managed runners. Start free →