Can I build multiple solutions and push the results into one Sonarqube project?

Hello!

Sonarqube Edition & Verison - Data Center Edition / 9.6.1

I am trying to understand whether there is a way to build multiple solutions that contain both C++ and C# code and push that result into a Single Sonar Project.

Previously, When using Community Edition, We used to run the BEGIN step(with the project key) and using MSBuild, build all the solutions(one-by-one) and run the END step. (We run the scan this way using a bat file).

Now, since C++ can be scanned in the Data Center Edition using the build wrapper, we tried to include the buildwrapper into our .bat file as it is mentioned here, C/C++/Objective-C | SonarQube Docs

But the problem here is, the buildwrapper-output.json that is being generated in each build is getting overwritten every time when the next solution is built.

I would really appreciate any suggestions on whether the current way we are running it is correct/is there an appropriate way to run this to cover all the c++ files and get an accurate result.

Thank you in advance!!!

Hello @aravindnss and welcome to our community.

It seems you are doing something like:

BEGIN STEP (with /d:sonar.cfamily.build-wrapper-output=<buildwrapperoutput_directory>)
for each solution to build
  build-wrapper --out-dir <buildwrapperoutput_directory> <msbuild rebuild command for solution>
END STEP

Instead, you should have a script with

for each solution to build
  <msbuild rebuild command for solution>

And then, you should do the following:

BEGIN STEP (with /d:sonar.cfamily.build-wrapper-output=<buildwrapperoutput_directory>)
  build-wrapper --out-dir <buildwrapperoutput_directory> script
END STEP

Does it help?

Hi @Geoffray,

Apologies for the late response and thank you so much for your reply.

I did try running it the way you suggested but I get the following error saying the BuildWrapperDump.json is empty.

ERROR: Error during SonarScanner execution
java.lang.IllegalStateException: The "build-wrapper-dump.json" file was found empty. Please make sure that:
  * you are using the latest version of the build-wrapper and the CFamily analyzer
INFO: ------------------------------------------------------------------------
  * your compiler is supported
  * you are wrapping your build correctly
  * you are wrapping a full/clean build
  * if you are building your project inside a Docker container, build-wrapper is wrapping the build process inside the container and not wrapping the external Docker process
        at com.sonar.cpp.plugin.CFamilySensor.process(CFamilySensor.java:459)
        at com.sonar.cpp.plugin.CFamilySensor.execute(CFamilySensor.java:202)
        at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:64)
        at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:88)
        at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:64)
        at org.sonar.scanner.scan.SpringModuleScanContainer.doAfterStart(SpringModuleScanContainer.java:81)
        at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:188)
        at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:167)
        at org.sonar.scanner.scan.SpringProjectScanContainer.scan(SpringProjectScanContainer.java:396)
        at org.sonar.scanner.scan.SpringProjectScanContainer.scanRecursively(SpringProjectScanContainer.java:392)
        at org.sonar.scanner.scan.SpringProjectScanContainer.doAfterStart(SpringProjectScanContainer.java:361)
        at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:188)
        at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:167)
        at org.sonar.scanner.bootstrap.SpringGlobalContainer.doAfterStart(SpringGlobalContainer.java:135)
        at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:188)
        at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:167)
        at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:72)
        at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:66)
        at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:567)
        at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
        at com.sun.proxy.$Proxy0.execute(Unknown Source)
        at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
        at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
        at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
        at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
        at org.sonarsource.scanner.cli.Main.main(Main.java:61)
ERROR:
The SonarScanner did not complete successfully

Let me know if there are any more details you want me to share.

Thanks again for helping me with this!

Hi @Arvinder_Chopra

Are you sure you are doing a clean build (a rebuild)?
So your entire build is done in one script which is passed to the build wrapper?
Are you using docker containers to build?

Hi @Geoffray,

I missed the rebuild part, but after adding that I could run the scan successfully.

Thank you so much for your help :slight_smile:

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