It seems you forgot to add the calls to cat in your .gitlab-ci.yml file.

You should have something like that:

script:
    - mvn $MAVEN_CLI_OPTS test
    - cat target/site/jacoco/index.html

That being said, I don't think this is the best way of doing this, as you need to pollute your output with raw HTML in order to retreive the desired coverage value.

I would recommend using the method described in this pull request instead: https://github.com/jacoco/jacoco/pull/488

  • Keep the jacoco parts in your build.xml
  • Use this awk instruction to print the correct code coverage total:

    awk -F"," '{ instructions += $4 + $5; covered += $5 } END { print covered, "/", 
    instructions, "instructions covered"; print 100*covered/instructions, "% 
    covered" }' target/site/jacoco/jacoco.csv
    
  • Replace the Gitlab CI regexp with what the instruction returns: \d+.\d+ \% covered

Edit:

As of Gitlab 8.17, you can define the regexp directly inside the .gitlab-ci.yml file, as stated in the documentation.

It may seem superfluous, but if this regexp is now part of your repository history, you can change it alongside the other tools used to compute it.

Answer from SKBo on Stack Overflow
🌐
GitHub
gist.github.com › rishitells › 3c4536131819cff4eba2c8ab5bbb4570
Setting up Jest tests and coverage in GitLab CI · GitHub
In the root of your project, add .gitlab-ci.yml with the configuration below. image: node:latest stages: - build - test build: stage: build script: - yarn cache: paths: - node_modules/ artifacts: expire_in: 1 days when: on_success paths: - node_modules/ test: stage: test coverage: /All files[^|]*\|[^|]*\s+([\d\.]+)/ dependencies: - build script: - yarn test:ci artifacts: when: always reports: junit: - junit.xml cobertura: coverage/cobertura-coverage.xml
Top answer
1 of 9
47

It seems you forgot to add the calls to cat in your .gitlab-ci.yml file.

You should have something like that:

script:
    - mvn $MAVEN_CLI_OPTS test
    - cat target/site/jacoco/index.html

That being said, I don't think this is the best way of doing this, as you need to pollute your output with raw HTML in order to retreive the desired coverage value.

I would recommend using the method described in this pull request instead: https://github.com/jacoco/jacoco/pull/488

  • Keep the jacoco parts in your build.xml
  • Use this awk instruction to print the correct code coverage total:

    awk -F"," '{ instructions += $4 + $5; covered += $5 } END { print covered, "/", 
    instructions, "instructions covered"; print 100*covered/instructions, "% 
    covered" }' target/site/jacoco/jacoco.csv
    
  • Replace the Gitlab CI regexp with what the instruction returns: \d+.\d+ \% covered

Edit:

As of Gitlab 8.17, you can define the regexp directly inside the .gitlab-ci.yml file, as stated in the documentation.

It may seem superfluous, but if this regexp is now part of your repository history, you can change it alongside the other tools used to compute it.

2 of 9
19

GitLab employee here.

If your administrator has GitLab pages set up, you can see the URL that your artifact deployed to by going (on your project) to Settings -> Pages.

There you should see:

Congratulations! Your pages are served under: https://your-namespace.example.com/your-project

Click on that link and you should be good to go! Also we are expanding support for HTML artifacts. This issue and it’s related issues talk about existing and upcoming features that may expand on what you’ve built here.

Discussions

How can I set a minimum unit test coverage with GitLab CI? - Stack Overflow
I can't find anything in the doc, except the keyword coverage that grabs the coverage to display on the main page. I would like something like this in .gitlab-ci.yml: More on stackoverflow.com
🌐 stackoverflow.com
How to retrieve unit test coverage values using .gitlab-ci.yml
My tool versions are:- cmake version 3.7.2 LCOV version 1.14-3-gebfeb3e Excerpt from my .gitlab-ci.yml looks like the following: Now I have the my coverage running on the pipeline and values get printed on the Gitlab terminal. The issue I am facing now is :- I am no... More on forum.gitlab.com
🌐 forum.gitlab.com
3
0
February 11, 2021
laravel - How can I access current Code Coverage Value in gitlab-ci.yml file - Stack Overflow
I'm trying to run jobs if my code coverage exceeds 80%. I have a laravel(10.x) project and I successfully generated code coverage of my and project Here is my code coverage calculated. Code Coverag... More on stackoverflow.com
🌐 stackoverflow.com
How latest GitLab versions improves using CI with monorepos

Thanks for sharing, interesting to see an example for a monorepository.

More on reddit.com
🌐 r/devops
8
41
June 16, 2018
🌐
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.
🌐
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 · 简体中文 · 日本語
🌐
GitHub
github.com › diffblue › gitlab › blob › master › doc › ci › testing › test_coverage_visualization.md
gitlab/doc/ci/testing/test_coverage_visualization.md at master · diffblue/gitlab
test: script: - npm install - npx ... .gitlab-ci.yml example for Java or Kotlin uses Maven to build the project and JaCoCo coverage-tooling to generate the coverage artifact....
Author: diffblue
Find elsewhere
🌐
DEV Community
dev.to › lazypro › gitlab-ci-for-node-testing-and-coverage-2ik3
Gitlab CI for Node Testing and Coverage - DEV Community
June 6, 2022 - The full .gitlab-ci.yml, which includes all mentioned features, is as follows. test_ci: script: - npm run test artifacts: paths: - coverage/ reports: junit: - test-results.xml coverage_report: coverage_format: cobertura path: coverage/cobertura-coverage.xml coverage: '/All files\s+\|\s+\d+\.\d+/'
🌐
GitLab
forum.gitlab.com › how to use gitlab
How to retrieve unit test coverage values using .gitlab-ci.yml - How to Use GitLab - GitLab Forum
February 11, 2021 - Hi all, We have a CMake based build and test system for our C/C++ based project. I am trying to integrate unit test code coverage in our CI/CD pipeline. The commands which I use for coverage processing are lcov and genhtml. My tool versions are:- cmake version 3.7.2 LCOV version 1.14-3-gebfeb3e Excerpt from my .gitlab-ci.yml looks like the following: Now I have the my coverage running on the pipeline and values get printed on the Gitlab terminal.
🌐
GitLab
docs.gitlab.com › ee › user › project › merge_requests › test_coverage_visualization.html
Sign in · GitLab
March 29, 2022 - When you visit any website, it may store or retrieve information on your browser, mostly in the form of cookies. This information might be about you, your preferences, or your device, and is mostly used to make the site work as you expect. The information does not usually identify you directly, ...
🌐
GitLab
gitlab.com › gitlab.org › repository
lib/gitlab/ci/templates/Security/Coverage-Fuzzing.gitlab-ci.yml · master · GitLab.org / GitLab · GitLab
May 10, 2023 - GitLab is an open source end-to-end software development platform with built-in version control, issue tracking, code review, CI/CD, and more. Self-host GitLab on your own servers, in a...
🌐
GitLab
docs.gitlab.com › gitlab docs › use gitlab › use ci/cd to build your application › testing › code coverage
Code coverage | GitLab Docs
Coverage reporting extracts a percentage from your test tool’s job log output. You define a regular expression in the coverage keyword.
🌐
Medium
medium.com › slickteam › manage-tests-and-coverage-in-gitlab-ci-4ccf0ddae34a
Manage tests and coverage in Gitlab-CI | by Ronan Barbot | Slickteam | Medium
May 11, 2021 - Since we have 2 stages for testing, we want to have the global results with unit and integration test coverage merged. In the gitlab-ci.yml file, we have set JaCoCo report folders as artifacts for the 2 stages, and declare the stage unit_test as a dependency of IT_test.
🌐
GitHub
github.com › viezel › GitLab-CI-Scripts › blob › master › .gitlab-ci-php-coverage-report.yml
GitLab-CI-Scripts/.gitlab-ci-php-coverage-report.yml at master · viezel/GitLab-CI-Scripts
# Gitlab CI configuration with PHP Code Coverage HTML report · # We merge multiple suits coverage reports and save those for download · # · stages: - test · · cache: # cache per-job and per-branch · key: "$CI_BUILD_NAME/$CI_BUILD_REF_NAME" paths: - vendor/ ·
Author: viezel
🌐
GitLab
docs.gitlab.com › gitlab docs › use gitlab › use ci/cd to build your application › ci/cd yaml syntax reference › artifacts reports
CI/CD artifacts reports types | GitLab Docs
For security report types (sarif, sast, dast, container_scanning, dependency_scanning, secret_detection, api_fuzzing, and coverage_fuzzing), the artifact is always uploaded but findings are only ingested when the producing job succeeds. A failed job, including one with allow_failure: true, does not produce ingested findings.
🌐
Aldec
aldec.com › support › resources › documentation › application notes › code coverage visualization in gitlab
Code Coverage Visualization in GitLab - Application Notes - Documentation - Resources - Support - Aldec
GitLab uses CI/CD's artifacts reports feature to collect the coverage information. You can specify one or more coverage report to collect, including wildcard paths. This change should be applied into the .yml file. For the coverage analysis to work, you have to provide a properly formatted ...
🌐
Cypress
cypress.io › blog › 2019 › 10 › 22 › show-code-coverage-on-gitlab-ci
Show Code Coverage on GitLab CI
May 5, 2021 - $ npx nyc report --reporter=text-summary ==== Coverage summary ============ Statements : 72.59% ( 98/135 ) Branches : 53.06% ( 26/49 ) Functions : 56% ( 28/50 ) Lines : 77.88% ( 88/113 ) ================================== GitLab CI can detect ...
🌐
GitLab
apps.risksciences.ucla.edu › help › help
Code coverage · Testing · Ci · Help · GitLab
You can display test coverage results in a merge request by adding the coverage keyword to your project's .gitlab-ci.yml file.
🌐
GitLab
genboree.org › help
Test coverage visualization · Testing · Ci · Help · GitLab
test: script: - npm install - npx ... .gitlab-ci.yml example for Java or Kotlin uses Maven to build the project and JaCoCo coverage-tooling to generate the coverage artifact....