12

We have a Jenkins job that contains a bunch of javascript files. We build our project via grunt, and at the end of the build we run JSCover to run our unit tests and collect code coverage. It all works. We get a nice LCOV file.

We now want to upload the LCOV file to Sonar, and I'm not sure how to do this. We are building our project from Jenkins as a free style project.

I tried playing around with various project properties for sonar, but no love:

# project metadata (required)
sonar.projectKey=my.project
sonar.projectName=My Project
sonar.projectVersion=1.0
# path to source directories (required)
sonar.sources=src

# The value of the property must be the key of the language.
sonar.language=java (I tried js and javascript, but no love. Plugin is not installed.  Actually, I don't care about the language, since I am already generating the LCOV file during the build.  I just need Sonar to use this LCOV file.)

# Advanced parameters
sonar.javascript.jstestdriver.reportsfolder=target/surefire-reports
sonar.javascript.jstestdriver.coveragefile=target/test-coverage/jscover.lcov
sonar.dynamicAnalysis=reuseReports

I suspect the problem is under the "Advanced Parameters", but I don't know how to tell Sonar, "Please use my LCOV file for Code Coverage".

grayaii
  • 2,241
  • 7
  • 31
  • 47

1 Answers1

12

You can have a look at this sample project where the path to a LCOV report is specified in the sonar-project.properties file.

Note that some property names have changed in the last version of the Javascript plugin.

  • 2
    Ah, looking at the link you posted, I see that the trick was to add this: sonar.javascript.jstestdriver.coveragefile=target/test-coverage/jscover.lcov sonar.javascript.lcov.reportPath=target/test-coverage/jscover.lcov – grayaii Apr 02 '13 at 14:19
  • 3
    The JsTestDriver no longer exists. They do have [another Javascript](https://github.com/SonarSource/sonar-examples/tree/master/projects/languages/javascript/javascript-sonar-runner-lcov) project which I found helpful. – cazzer Apr 11 '14 at 15:32
  • @Fabrice-SonarSourceTeam the paths that are generated by istambul. which is used by karma coverage are absolute and in the example they are relative. How are most teams solving this issue? – miguelr Nov 29 '16 at 07:21
  • @miguelr If you run both karma and then SonarQube scanner from the root folder of your project, this should be fine - even if the path are absolute. – Fabrice - SonarSource Team Nov 29 '16 at 13:19
  • Thanks for the notification, I changed the link to another project that is maintained. – Fabrice - SonarSource Team Sep 14 '17 at 10:19
  • Thank you for sharing that, I figured out my problem was the lcov.info file was specifying local relative paths, and my sonar-scanner command was being run from the project root. – SSH This Nov 11 '20 at 18:51
  • I have generated LCOV for my go code. Can I use the same or are there different parameters? – AhmFM Dec 14 '22 at 01:14