How to put Node package version into sonar.projectVersion

Using SonarCube 1.1.9

I have a NodeJS project. It has a package.json file which has a version in it. I also has a sonar-properties.project file. in the project file there’s a sonar.projectVersion key and it is set to a version. This is the version that shows up in the SonarCube analysis.

How do I get SonarCube to use the version from the package.json file so that I don’t have to maintain the version in 2 places?

There is a community scanner
It relies on package.json file to generate analysis properties.

1 Like

First of all - Awesome! Thank you Elena!

I’m doing this in a (very large) corporate environment and currently I can’t even find the team that maintains our Sonar instance. I’m also new to this. I read through the Readme on this package. It’s not clear to me where this runs and pushes (?) the data to. Our current environment has Sonar running on the CI server and expecting a sonar-properties.project file in the root.

Can anybody expand my knowledge on how this Node community scanner would work in this context? Thanks.

You can get inspired from this example, there a JS script is used to launch analysis.
You can also launch scanner with command line (see docs of sonarqube-scanner package).

To specify where to push the data, use scanner property serverUrl.

1 Like