node.jsjestjsgitlab-cigitlab-ci-runnercobertura

Gitlab CI not showing Cobertura code coverage visualization


I am trying to show test coverage visualization in Gitlab for our monorepo as described here Test Coverage Visualization

We are using a self-managed gitlab runner with the docker+machine executor hosted on AWS EC2 instances. We are using Gitlab SaaS. The job from the gitlab-ci.yml is below

sdk:
  stage: test
  needs: []
  artifacts:
    when: always
    reports:
      cobertura: /builds/path/to/cobertura/coverage/cobertura-coverage.xml
  <<: *main
  <<: *tests
  <<: *rules
  <<: *tags

The line in the script that runs the tests and outputs code coverage...

- npm run test -- --watchAll=false --coverage --coverageReporters=cobertura

The artifact gets saved just fine and looks normal when I download it, but I don't get any visualization as described in the documentation linked above. I just updated the gitlab runner to V14.0.0 thinking that might be the problem, it's not.

I don't have any sort of regex pattern setup, as from my understanding that is only for printing the coverage to stdout.

I'm sure I am overlooking something trivial and I really need a sanity check here as I have already spent way more time on this than I can afford.


Solution

  • The issue was that the regex pattern needed to be set in the repository settings. I had experimented with adding a regex pattern, but it hadn't worked by the time I posted this question because the regex pattern I was using was not correct.