4

I have CI setup for a GitLab repository and the job contains the following output to the STDOUT.

=============================== Coverage summary ===============================
Statements   : 94.25% ( 291/333 )
Branches     : 62.29% ( 53/75 )
Functions    : 73.32% ( 170/196 )
Lines        : 94.68% ( 533/569 )
================================================================================

In the .gitlab-ci.yml file for the job I have the coverage: /^Statements\s*:\s*([^%]+)/. As well, in the CI/CD settings for the repository I have ^Statements\s*:\s*([^%]+) set.

Yet code coverage appears to be Unknown on the code coverage badge.

Adam Thompson
  • 3,278
  • 3
  • 22
  • 37

2 Answers2

2

You might need to set the multiline flag

coverage: /^Statements\s*:\s*([^%]+)/m
#                                   ^^^
Jan
  • 42,290
  • 8
  • 54
  • 79
  • Good thought. I looked into the core build runner code and found the following which leads me to believe it uses multiline already https://gitlab.com/maxraab/gitlab-ce/blob/master/lib/gitlab/ci/trace/stream.rb#L68 – Adam Thompson Feb 11 '18 at 20:58
1

Turns out that the build needs to be passing. So a Mocha exception for example of a failing test will prevent code coverage from being extracted.

Adam Thompson
  • 3,278
  • 3
  • 22
  • 37
  • can you please share your .yml file (or a part of it where you fixed it), I'm having the same issue –  Dec 06 '18 at 22:58
  • @YashKaranke in my case the build needed to be passing in order for the coverage to be parsed and displayed. – Adam Thompson Dec 07 '18 at 00:28