3
votes

Sonar does not retrieve the coverage information for my project when paths are absolute in my lcov file. For the file:

TN:
SF:/mnt/vg01-data01/jenkins/<jenkins.myhost.com>/jenkins_home/workspace/<job1>/src/app.js
FN:,(anonymous_0)
FN:,(anonymous_1)
FNF:2
FNH:2
FNDA:1,(anonymous_0)
FNDA:2,(anonymous_1)
DA:3,1
DA:4,1
DA:6,1
DA:7,1
DA:8,1
DA:9,1
DA:11,1
DA:18,1
DA:19,1
DA:22,2
DA:27,1
LF:11
LH:11
BRF:0
BRH:0
end_of_record
....

I get the following warnings:

...
05:06:27.565 INFO: Analysing [/srv/jenkins/<jenkins.myhost.com>/jenkins_home/workspace/<job1>/coverage/lcov.info]
05:06:27.574 DEBUG: Default value of zero will be saved for file: src/app.js
05:06:27.574 DEBUG: Because was not present in LCOV report.
05:06:27.578 DEBUG: Default value of zero will be saved for file: src/app.spec.js
05:06:27.578 DEBUG: Because was not present in LCOV report.
05:06:27.579 DEBUG: Default value of zero will be saved for file: src/js/form/form.ctrl.js
05:06:27.579 DEBUG: Because was not present in LCOV report.
05:06:27.580 DEBUG: Default value of zero will be saved for file: src/js/form/form.module.js
05:06:27.580 DEBUG: Because was not present in LCOV report.
05:06:27.581 DEBUG: Default value of zero will be saved for file: src/js/success/success.ctrl.js

...

However, by default karma (and istambul) are generating file with absolute paths.

If I change the paths to make them relative, sonarqube reports the coverage correctly. However, I must ensure a "lcov patch" script is always run before reporting to sonar.

Does sonar support absolute paths? What are other teams doing for this issue? These are the versions I am using:

Update: I replaced the file and log I see with the exact ones from the jobs (I still must change the name of the host and job for security reasons.)

Update March 2016: I have sent a Pull Request to Istambul to enable to generate lcov file with relative paths. I expect this to solve this issue https://github.com/gotwarlost/istanbul/pull/771

1

1 Answers

4
votes

The SonarQube JavaScript plugin should be able to handle both relative and absolute paths in LCOV files. However, it seems that your setup is incorrect. Your LCOV file refers to file paths in a given directory:

SF:/home/mrincon/work/git/promoter-app-client/src/app.js

And based on the logs of your analysis, it seems that your analysis is run in another directory:

Analysing [/srv/jenkins/master/jenkins_home/workspace/job1/coverage/lcov.info]

Maybe you generated the LCOV file on one machine and run the analysis on another... In the end, SonarQube can't match the paths contained in the LCOV file with the files which are analysed.

You should either:

  • generate the LCOV report and run the SonarQube analysis from the same directory,
  • or have your LCOV file contain only relative paths.