Thanks! Did the following and the badge works: Added an extra grep to show the text coverage text without ANSI (I want colour for my test output). Add the coverage regex as mentioned. Thanks for the help. Answer from yookoala on forum.gitlab.com
🌐
GitLab
docs.gitlab.com › gitlab docs › use gitlab › organize work with projects › badges
Badges | GitLab Docs
Then you can use the link to embed the badge in your HTML or Markdown pages. In the top bar, select Search or go to and find your project. In the left sidebar, select Settings > CI/CD. Expand General pipelines. In the Pipeline status, Coverage report, or Latest release sections, view the URLs ...
🌐
GitLab
docs.gitlab.com › gitlab docs › use gitlab › use ci/cd to build your application › testing › code coverage
Code coverage | GitLab Docs
Coverage badges. The Coverage-Check approval rule (Premium and Ultimate), which can require approval when coverage drops. For setup instructions, see configure coverage reporting. Coverage visualization parses a Cobertura or JaCoCo XML report that your test job uploads as a CI/CD artifact.
Discussions

Coverage badge in Gitlab CI with Python coverage always unknown - Stack Overflow
I am trying to show a coverage badge for a Python project in a private Gitlab CE installation (v11.8.6), using coverage.py for Python. However, the badge always says unknown. This is the relevant j... More on stackoverflow.com
🌐 stackoverflow.com
How to create a Gitlab CI coverage badge for R - Stack Overflow
Being not familar with R myself, I'd like to create a badge to summarize the test coverage in Gitlab CI, using the covr package. The only way I found on the net was to use the gitlab function; howe... More on stackoverflow.com
🌐 stackoverflow.com
testing - Gitlab coverage badge always unknow - Stack Overflow
I also found that if you don't ... the badges will continue to report out "unknown" for code-coverage. 2022-01-24T19:12:37.9Z+00:00 ... Update 2022 - "This feature is in its end-of-life process. It was deprecated in GitLab 14.8. The feature is removed in GitLab 15.0." From Gitlab Docs 2022-10-03T05:52:49.377Z+00:00 ... @Sagivb.g yes it's deprecated, they added a parameter in gitlab-ci.yaml - coverage ... More on stackoverflow.com
🌐 stackoverflow.com
Gitlab Coverage badge not working - Stack Overflow
I am deploying Django application using Gitlab CI/CD and pytest for testing of code and pytest-cov for generating coverage report My .gitlab-ci.yml stages: - test - deploy image: python:3.6 ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
GitLab
forum.gitlab.com › gitlab ci/cd
How to trigger Coverage badge and Test Coverage Visualization with cobertura coverage xml? - GitLab CI/CD - GitLab Forum
January 18, 2022 - I’m trying to trigger proper coverage badge generation and test coverage visualization for one of my pet project. This is my current config file. I have successfully generated a Cobertura format xml for my coverage that stores in tests/_output/cobertura.xml.
🌐
Patricksoftwareblog
patricksoftwareblog.com › add_badges_to_a_gitlab_project.html
Add Badges to a Python Project in GitLab | Patrick's Software Blog
October 26, 2021 - Start with a Python project in ... ‘Test Coverage’ badge uses a regex (Regular Expression) to parse the results of running a test coverage job in the CI (Continuous Integration) pipeline....
Top answer
1 of 5
20

I finally got the coverage badge displaying a percentage instead of unknown today for my python project. Here's the relevant content from my .gitlab-ci.yml:

job:
 script:
  - 'python -m venv venv'
  - '.\venv\Scripts\activate'
  - 'python -m pip install -r requirements.txt'
  - 'coverage run --source=python_project -m unittest discover ./tests'
  - 'coverage report --omit=things_that_arent_mine/*'
  - 'coverage xml'
 artifacts:
  reports:
   cobertura: 'coverage.xml'

I'm also using the regex for gcovr listed in the repo CI/CD Settings > General Pipelines > Test coverage parsing which I found after reading this as well as the second to last comment on this:

^TOTAL.*\s+(\d+\%)$

In the repo General Settings > Badges, my badge link is:

http://gitlab-server/%{project_path}/-/jobs

and my badge image url is:

http://gitlab-server/%{project_path}/badges/%{default_branch}/coverage.svg

I don't quite know what the Cobertura report artifact is for (I think it specifically has to do with merge requests) but I have it in there because the tutorials took me down that road. I did confirm that removing the following from the .gitlab-ci.yml doesn't break the badge or coverage number on the jobs page:

  - 'coverage xml'
 artifacts:
  reports:
   cobertura: 'coverage.xml'

While removing or commenting:

- 'coverage report --omit=things_that_arent_mine/*'

does break the badge as well as the coverage number displayed on the CI/CD jobs page of the repo. I also tried some regex variations that I tested in rubular but the only one that didn't cause gitlab to barf was the gcovr one.

Hopefully this helps out, it was kind of difficult and arduous to piece together what was needed for this badge to work on a python project.

EDIT: Also just figured out how to add some sexy precision to the coverage percentage number. If you change the coverage report line of the .gitlab-ci.yml to:

- 'coverage report --omit=things_that_arent_mine/* --precision=2'

And the regex in CI/CD Settings > General Pipelines > Test coverage parsing to:

^TOTAL.+?(\d+.\d+\%)$

That should give you a very precise coverage number that effectively no one but you and I will care about. But by gosh we'll know for sure if coverage is 99.99% or 100%.

2 of 5
6

A solution that worked for me:

In the .gitlab-ci.yml file, in the job that runs the coverage report, I added the following lines:

  script:
    # some lines omitted for brevity
    - coverage report --omit=venv/*
  coverage: '/TOTAL.*\s+(\d+\%)/'

In particular, I couldn't get the badge to show anything but unknown until I added the coverage directive to my test job. Bear in mind, different tools may print different output and so you will likely have to change the regular expression, as I did.

🌐
Stack Overflow
stackoverflow.com › questions › 67818088 › how-to-create-a-gitlab-ci-coverage-badge-for-r
How to create a Gitlab CI coverage badge for R - Stack Overflow
... Save this answer. ... Show activity on this post. usethis::use_gitlab_ci() provides a useful template to set up GitLab CI/CD for R packages which in turn can be used to create coverage badges.
🌐
Calebukle
calebukle.com › blog › angular-code-coverage-badge-with-gitlab-ci
Generate Code Coverage Badge with Gitlab CI and an Angular Project - Caleb Ukle
Next time you run your pipeline Gitlab will capture the output and update the badge with the code coverage percentage! As promised, I’ll talk a little about setting up a Gitlab pipeline for testing Angular applications. Right up front here is my .gitlab-ci.yml
Find elsewhere
Top answer
1 of 3
20

I was struggling with this too for a python project and found that the test coverage results is now deprecated (https://docs.gitlab.com/ee/ci/pipelines/settings.html#add-test-coverage-results-to-a-merge-request-deprecated)

The answer for me was to use the coverage keyword in my .gitlab-ci.yml with the required regex to extract the percentage from the job log

e.g.

test:
  stage: test
  extends: .python-reports
  script:
    - pipenv run pytest --cov --cov-report term-missing --cov-report xml:./coverage_out_report.xml --junitxml=./test_out_report.xml
  coverage: '/TOTAL.*\s+(\d+%)$/'

And my badge defined as

Link https://gitlab.com/%{project_path}/-/commits/%{default_branch}

Badge image URL https://gitlab.com/%{project_path}/badges/%{default_branch}/coverage.svg

Now I see the coverage as 100% on main (or master) and a nice green badge

2 of 3
12

I had the same issue in a different stack (Java, Gradle, and Jacoco). I've already solved the issue, and I will share what I've done. I hope my solution gives you some idea.

First, In your project, go to Settings > CI/CD and expand the General pipelines section. Fill the Test coverage parsing textbox with an appropriate regular expression based on the tool you are using. You can find the sample list of these regular expressions on this page: Test coverage parsing samples

Gitlab expects that the test runner tool will print the test coverage percent based on the given regular expression somewhere on the CI job's log. If the test runner engine doesn't print it to the console, you can do it manually. For instance:

test:
  stage: test
  script:
    - gradle test jacocoTestReport --info
    # Print test coverage to console
    - cat build/reports/jacoco/test/html/index.html | grep -o 'Total[^%]*%'
  artifacts:
    paths:
      - build/reports/jacoco/test/*

After making sure that the test coverage exists in the log, the badge will work perfectly.

pipeline and coverage badge sample

🌐
Timesofcloud
timesofcloud.com › home › gitlab cicd
GitLab CI/CD Tutorial — Pipeline Badges -
September 30, 2025 - [![coverage](https://gitlab.co... to extract the coverage percentage from the job log. You can add custom badges via Settings → CI/CD → General pipelines → Pipeline status badges....
🌐
GitLab
docs.gitlab.com › gitlab docs › use gitlab › use ci/cd to build your application › pipelines › customize pipeline configuration
Customize pipeline configuration | GitLab Docs
You can use pipeline badges to indicate the pipeline status and test coverage of your projects. These badges are determined by the latest successful pipeline. GitLab CI/CD pipelines are enabled by default on all new projects.
🌐
KodeKloud Notes
notes.kodekloud.com › optimization, security and monitoring › adding a pipeline status amp code coverage badge
Adding a Pipeline status amp Code Coverage Badge - KodeKloud
January 28, 2026 - GitLab will automatically generate two badge URLs: Pipeline status: Reflects the last pipeline’s outcome. Coverage report: Shows the test coverage percentage only if a coverage job exists.
🌐
GitHub
gist.github.com › rishitells › 3c4536131819cff4eba2c8ab5bbb4570
Setting up Jest tests and coverage in GitLab CI · GitHub
This script is used in the test ... expression is used to find test coverage output in the job log. This coverage % can be viewed on Project > CI/CD > Jobs. We can also configure Badges on Project Overview page to show coverage ...
🌐
GitLab
forum.gitlab.com › gitlab ci/cd
Populate code coverage badge stats - GitLab CI/CD - GitLab Forum
June 27, 2022 - Issues populating code coverage badge, badge showing ‘unknown’ Swift project. I am seeing a cobertura.xml file associated with a merge request, after numerous attempts to configure the coverage value in the .gitlab-ci.yml the value is still reporting ‘unknown’. Unfortunately the test ...
🌐
GitLab
forum.gitlab.com › gitlab ci/cd
Coverage badge unknown - GitLab CI/CD - GitLab Forum
April 27, 2018 - I seem to be unable to show the coverage percentage on a badge though. I followed this tutorial here: So I have this set into my .gitlab-ci.yml rspec: stage: test script: - rspec artifacts: paths: - coverage/ pages: stage: deploy dependencies: - rspec script: - mv coverage/ public/ artifacts: ...
🌐
HackerNoon
hackernoon.com › adding-test-coverage-badge-on-github-without-using-third-party-services
Adding Test Coverage Badge on GitHub Without Using Third-party Services | HackerNoon
August 8, 2022 - It’s easy to add test coverage on GitLab using the built-in feature. One line in .gitlab-ci.yml to rule them all: ... On the opposite side, GitHub doesn’t provide an option to add the test coverage badge. There are many third-party services for this purpose: codeclimate, codecov, codacy, coveralls.
🌐
Medium
mennan-sevim.medium.com › how-to-use-custom-gitlab-badges-212062a1d019
How To Use Custom GitLab Badges?. In this article, I want to tell you… | by Mennan Sevim | Medium
April 12, 2022 - Gitlab badges are a visual way of presenting summary information about your projects. They consist of a small image and a URL that the image points to as a link. We can use badges for example to show information about pipeline status, test coverage, ...
🌐
GitLab
docs.gitlab.com › ee › ci › testing › test_coverage_visualization.html
Test coverage visualization
Sign in to GitLab · By signing in you accept the Terms of Use and acknowledge the Privacy Statement and Cookie Policy · Don't have an account yet? Register now · or sign in with · Remember me · Explore Help About GitLab GitLab community forum · English · 简体中文 · 日本語
🌐
Gitlab
gitlab-docs-d6a9bb.gitlab.io › use gitlab › organize work with projects › badges
Badges | GitLab
Then you can use the link to embed the badge in your HTML or Markdown pages. On the left sidebar, select Search or go to and find your project. Select Settings > CI/CD. Expand General pipelines. In the Pipeline status, Coverage report, or Latest release sections, view the URLs for the images.