Add to keys from the command line and not overwrite

which versions are you using

  • SonarQube: Version 9.5 Developer Edition
  • Scanner: SonarScanner

what are you trying to achieve
I want to specify global team level keys as part of the CI pipeline but with the ability to add to a specific key from the project specific “” file.
Globally our CI can exclude the “main.cpp” for all projects for coverage, thus I want the CI to add --define sonar.coverage.exclusions=src/**/main.cpp to the sonar scanner.
But I still want to be able to add specific other files per project, for example project A might add sonar.coverage.exclusions = src/version.cpp in its properties file.

what have you tried so far to achieve this
From my testing it appears that the command line option passed to sonar-scanner is the only one used. The option in the properties file is ignored/overwritten with the command line option.

Is there a way to support both without relying on each project adding these general files to their properties file?

Hey there.

While something like this is possible for excluding entire files from analysis ( – nothing like this exists for sonar.coverage.exclusions… and I’m not sure precisely why.

There’s a specific hierarchy where analysis parameters override each other, and no way to say “append” rather than “overwrite”.

What you could imagine doing is setting an environment variable with the global values for sonar.coverage.exclusions (like export GLOBAL_COVERAGE_EXCLUSIONS=src/**/main.cpp) and then have your users reference the environment variable and append any special files. It’s not a perfect solution.

I’m also happy to move your post to Product Manager for a Day - Sonar Community

Hi Colin,

Thank you for the idea and good suggestion.

For the moment I have a workaround that caters for my immediate need without the need for such a feature, thus I am happy to close the ticket here.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.