0

I have managed to show code coverage data with Cobertura XML in Jenkins. Its works well, but I wants to see the source code in Jenkins, too. I accidentally saw, that Jenkins is referring for the source files at my windows harddrive, but the files are on a Jenkins server (different PC). This happens maybe, because in Cobertura output XML, the "filename" refers to an absolute path and not relative from directory. The XML attribute looks like filename="C:/Users/PathToMySources".

How I can change filenames in Cobertura XML to be relative?

gcovr.exe is invoked like this:

gcovr.exe --filter ../MySources/ --branches --html-details Test.html --cobertura Test.xml

My Project look like this:

MyProject
|
|---Library A (has subfolders)
|
|---Library B (has subfolders)
|
|---TestFolder for Library A and B (has subfolders)

This Layout is like this because Library A, B and Testfolders are externals in svn for sharing the library to everyone in the company. With gcovr I refered for example to Library B. In Library B, I have subfolders. Some Subfolders contains only headers because of template classes in C++. Now I saw another issue. With --filter, the header only classes are included in coverage output, with --root they are not included!

1 Answers1

1

In this instance, you can fix things by changing --filter to --root.

Gcovr has a concept of a “root” directory which defaults to the current working directory. The root is used for various purposes like serving as a default filter, but also for deciding how file names are presented in reports.

  • If a file path is within the root directory, a path relative from the root directory is shown.
  • Otherwise, an absolute path is shown

It is unusual to ever see an absolute path in a gcovr report, unless you're trying to include coverage for a library outside of your project directory, or if you're using the --html-absolute-paths option.

amon
  • 57,091
  • 2
  • 89
  • 149
  • @user19471767 Could you edit the information about your project layout into the question? – amon Jul 16 '22 at 19:12
  • Well with --root, I have no coverage data. I have no input in html files, it is empty. Ok I solved that problem now, but I opened a new problem. Now I have no coverage data for my header only template classes :( – user19471767 Jul 16 '22 at 19:31
  • @user19471767 This might need a more complicated invocation where the root covers both your libraries and your current working directory, and you use a filter to narrow down the report. For example `gcovr --root ../ --filter ../LibraryB OTHER_OPTIONS`. – amon Jul 16 '22 at 20:25
  • This made the trick. Thank you!! Now, I can see the source code in Jenkins! – user19471767 Jul 16 '22 at 20:56