How to retrieve unit test coverage values using .gitlab-ci.yml

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.

The issue I am facing now is :- I am not aware of what does this “coverage: regex” line is doing for me.
I thought this line would help me to retrieve the coverage values from the terminal prints and help me in introducing a check against coverage threshold values and fail the pipeline.

An alternate way would be to implement a shell script to read the terminal output and parse the coverage results and implement the coverage check in the script. But I would like to confirm if there are any Gitlab specific options that help me with that (eg: using this coverage line or any other).

Could you please guide me on that?
Thanking you for your time and understanding. Looking forward to hearing from you soon.

Best regards,
Honey Sukesan

1 Like

@lullaby - Thanks for posting and welcome to the forum!

The regex parses the value that is used by the Test Coverage Parsing to display the value in the pipeline area of the Merge Request page, the Coverage History Graph and can be used in badges.

There is not a way to block merge when coverage decreases in the product today but you can use a shell script as you described to check the value and fail the pipeline. We are working on an issue to build this into the product in the coming milestones. You can follow the progress here: Enforce Code Coverage for merge (&4366) · Epics · · GitLab.

-James H, GitLab Product Manager, Verify:Testing

1 Like

Thank you very much, James for your response.
One query please -
Does that also mean "coverage: " in .gitlab-ci.yml will also deliver the same results as “Test Coverage parsing” setting in Gitlab?

Best regards,

@lullaby - Yes those are equivalent. I hope this helped!

-James H, GitLab Product Manager, Verify:Testing