No coverage report in gitlab despite valid regex and activated parsing

Viewed 503

So I have a netstandard library with a test project, nothing too large. This gets built and tested by Gitlab CI via dotnet test and coverlet. Part of the test's output will be this coverage report:

+---------+--------+--------+--------+
|         | Line   | Branch | Method |
+---------+--------+--------+--------+
| Total   | 90.87% | 67.66% | 94.32% |
+---------+--------+--------+--------+
| Average | 90.87% | 67.66% | 94.32% |
+---------+--------+--------+--------+

Now Gitlab uses regex to parse that, so naturally I have this regex parsing the first value:

Total\s*\|\s*(\d+\.\d+)%

I put it in in the coverage parsing setting under settings > general pipelines, and also added coverage: /Total\s*\|\s*(\d+\.\d+)%/ to the job in the .gitlab-ci.yml. I validated the regex using rubular, as Gitlab suggested: https://rubular.com/r/LOazRNRFmChzIr and it confirms my regex will find that coverage amount.

And yet, there is no coverage to be seen anywhere. The badge I added to the project also shows "coverage: unknown".

Is something still missing?

3 Answers

Alright time to make myself look stupid.

I copypasted the table from my local machine's output into rubular.

Turns out the test runner uses commas a decimal separators, while my local machine uses periods. That is all.

Warning, as mentioned here by Drikus Roor, since GitLab 14.8, the test coverage parsing setting has been deprecated and has been removed since GitLab 15.0.

You would therefore no longer be able to set your (with commas) regex through Settings > CI/CD > General pipelines. But you would have to use the coverage setting in your GitLab CI/CD configuration file and use your regular expression in the setting value:

unit-test:
  stage: test
  coverage: 'Total\s*\|\s*(\d+\,\d+)%'
  ...

To allow for 100% coverage, you can use:

test:
  ...
  coverage: /Total\s*\|\s*(\d+\.?\d+)%/
Related