Set additional custom properties in sonar-scanner

I’m working on building a custom sonar plugin which displays some regular sonar information about projects (fethed from sonar’s REST API) + some additional information.
One such information I want to show is build tool used in the project (like Jenkins or GoCD).

But somehow I want to this info to be stored within sonar only, so that I can fetch this also using REST API.

I am wondering if this info can be set as a property in ‘sonar-project.properties’ & can be sent to sonarqube while preforming sonar-scanner.

Please suggest if this is possible or if there is a better approach to it.

Thank You

1 Like

Rahul,

As far as I understand, parameters that are set at analysis time only truly persist for the time that the analysis runs. As an example: if I set sonar.exclusions at analysis time, those settings are not reflected in the project administration section on SonarQube.

If you want to set information about the build tool – you might consider using the built-in sonar.links.ci parameter. Information about that and other similar parameters are available here. No custom development needed, although running reports might require some additional parsing of the provided URL.

You might also consider using a custom measure to add this additional metadata, but I’m wary of offering up that as an option as I don’t really like custom measures. That said, you could update a custom measure for “Build Tool” via REST API in your build right before running the analysis, as the analysis will make the custom measure “stick”.

By the way, the Plugin Development forum might be a better place for questions related to plugin development!

Colin

2 Likes

Hi Colin,

Thanks a lot.
sonar.links.ci parameter is actually what I was looking for. Just one question, how can I retrieve its value from REST call?

Using custom measure, I’m able to do it, but as you said I agree its not a better approach.

Regards

Rahul,

You would use the GET api/settings/values api (as long as you’re on SonarQube 6.3+). I don’t specifically recall which version the sonar.links.ci setting popped up, but I’ll just cop-out and say you should be running at least the current LTS (6.7.x) or above. :wink:

As always, the documentation for the Web API is located at http://[your instance]/web_api/

To grab a specific setting based on a project key (or as is more likely, to iterate through a list of project keys), use a call like this: http://[your instance]/api/settings/values?component=[projectKey]&keys=sonar.links.ci

Colin

Thanks again for the help. Technically you are right.
http://[your instance]/api/settings/values?component=[projectKey]&keys=sonar.links.ci
should show the value.
But for some reason it is not showing me, even though I’m using ver. 6.7.

Thank you