How to make work View history of project code coverage

How to fix View history of project code coverage

I am trying to set up Code coverage | GitLab

I am using GitLab v16.0

This is my yaml

# .gitlab-ci.yml

image: node:12

# Define the stages of the pipeline
stages:
  - test
  - pages

cache:
  paths:
    - node_modules/

# Define the job that will run tests
test:
  stage: test
  script:
    - npm install
    - npm run test -- --coverage --verbose
  artifacts:
    when: always
    paths:
      - junit.xml
      - coverage/cobertura-coverage.xml
    reports:
      coverage_report:
        coverage_format: cobertura
        path: coverage/cobertura-coverage.xml
      junit: junit.xml
  # Add coverage to code coverage statistics
  coverage: '/All files[^|]*\|[^|]*\s+([\d\.]+)/'

  # Define when this job should be executed
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"'

pages:
  stage: pages
  dependencies:
    - test
  script:
    - mv coverage/ public/
  artifacts:
    paths:
      - public
    expire_in: 30 days
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"'


Also when I try to use badges I get “uknown” as the result localdomain.com/parentfolder/project/badges/master/coverage.svg

Screenshot 2023-08-09 182951

The only thing i do see working is

@shorif2000

Once that MR Merges and the coverage job is run on the default branch those should both populate (coverage badge and the graph).

I hope this helps!

-James H, GitLab Product Manager, Analyze:Product Analytics

I have merged many PR’s with successful pipelines but I don’t see anything in Project->analytics->repository “Code coverage statistics for maste

It seems like it only appears in the branches. How do I make it save the coverage data for master branch?

My pipeline triggers on merge to master only

@shorif2000 - Oh sorry I’d forgotten what that drop down was for! It’s the different jobs that have the coverage calculation not the branch.

You can see the coverage-frontend job from the latest build of the default branch on the gitlab project matches up with the coverage percentage in the graph and the JS-Coverage badge on the project details. In this case the badge is setup to report coverage from that specific job (docs link).

Hopefully this helps better explain what those values are and where they are sourced from.

-James H, GitLab Product Manager, Analyze:Product Analytics