I need to do the entire SonarCloud analyze (SonarCloud scan, coverage, quality gate etc) of C/C++ code which is compiling on a specific Docker image. Such docker image is builded up inside Azure DevOps pipeline task and the tests are executed on agent directly (instead of the same docker image than build) in different pipeline stage.
I’ve investigate it a little bit and I am ready to put building the project and executing the tests to one docker image or make an additional docker image for executing tests and then export application and tests results directly to agent. As it is realized by Azure DevOps pipeline I’ve got no access to the Dockerfile in a simple way so I probably would have to prepare configuration of SonarCloud properties inside pipeline step or some script step before running the build/compiling the code pipeline step.
First I am creating the image file by docker build with parameters, then I am running this image by docker run and execute build.sh script with parameters to compile c/c++ application inside
Tips: the script to use is displayed when you create the SonarCloud project. Use the same script, for me it was : sonar-scanner.bat -D"sonar.organization=yous-sonar-organization" …
I’ve got my environment on Linux so the way to achieve it is a liitle bit different.
What have been done so far:
Download, unzip and add build-wrapper to the PATH in Dockerfile
Download, unzip and add sonar-scanner to the PATH (bin dir) in Dockerfile
Execute my build script (shell script with line arguments) with prefix like: build-wrapper-linux-x86-64 --out-dir during running the Docker container or even before make command inside this build shell script.
Directly after execute build script/make command inside the script I’ve tried to run sonar-scanner (followed by SC documentation) but looks like it doesn’t start any time.
Instead of executing sonar-scanner just after the build/make I’ve also tried to separate execution to different pipeline step or even run the docker with sonarcource/sonar-scanner-cli image like:
I’ve got no 100% sure if the step 4 or 5 is correct in this case.
I am trying to do as it is in documentation or on the SonarCloud config page but looks like it’s a little bit complicated if entire process have to be run on Docker. Am I right?
Hi Szymon,
For info I’m a SonarCloud user and I’m as well some time in trouble with SC doc. I never worked on Linux with SC.
I guess, that in your command, you need to add in your docker path, the path of the the sc scanner.
docker … no idea if we can do that with docker run -e PATH=$PATH:$sonar-scanner path.
yeah, but the question is should I run the sonar-scanner on docker or it will be enough to run sonar-scanner on local with the local path to the files used by docker container?
I am building an C++ app on Docker but so far it looks like even if I am trying to run sonar-scanner on this Docker container directly or run the build script with build-wrapper “prefix” (follow documentation) on this Docker then I can’t find anything inside the build log confirms that the build-wrapper or sonar-scanner works properly.
Sonar-scanner and Build-wrapper are properly download and uznipped through Dockerfile and its paths are properly added to the PATH env var (also through Dockerfile).
For me I ran sonar-scanner in the running container.
For the c++, the sonar-scanner have to be run first and then on the same running container the cc++ build have to be started.
The step to follow should be this, I do not have example as I never did it.
docker exec sonarscanner begin -/k:“…” /o:“…” /d:sonar.login=“$(EXAMPLE-TOKEN)” /d:sonar.host.url=“https://sonarcloud.io” /d:sonar… /d:sonar…
docker exec build c++ project
docker exec sonarscanner end /d:sonar.login=“$(EXAMPLE-TOKEN)”
Now, I’ve got another error: Java heap space at the end of sonar scan:
2023-09-27T12:10:59.7232822Z 12:10:59.722 INFO: Hit the cache for 0 out of 0
2023-09-27T12:10:59.7236300Z 12:10:59.723 INFO: Miss the cache for 0 out of 0
2023-09-27T12:10:59.7401480Z 12:10:59.739 DEBUG: the bridge server will shutdown
2023-09-27T12:11:04.7428624Z 12:11:04.742 DEBUG: the bridge server closed
2023-09-27T12:11:04.7428903Z 12:11:04.742 INFO: Time spent writing ucfgs 0ms
2023-09-27T12:11:05.3032575Z 12:11:05.302 INFO: ------------------------------------------------------------------------
2023-09-27T12:11:05.3032826Z 12:11:05.302 INFO: EXECUTION FAILURE
2023-09-27T12:11:05.3033214Z 12:11:05.302 INFO: ------------------------------------------------------------------------
2023-09-27T12:11:05.3033383Z 12:11:05.302 INFO: Total time: 17:48.562s
2023-09-27T12:11:05.4011755Z 12:11:05.400 ERROR: Error during SonarScanner execution
2023-09-27T12:11:05.4011979Z 12:11:05.400 INFO: Final Memory: 84M/512M
2023-09-27T12:11:05.4012568Z 12:11:05.400 INFO: ------------------------------------------------------------------------
2023-09-27T12:11:05.4012731Z java.lang.OutOfMemoryError: Java heap space
2023-09-27T12:11:05.4046575Z at java.base/java.lang.StringCoding.encodeASCII(Unknown Source)
2023-09-27T12:11:05.4046851Z at java.base/java.lang.StringCoding.encode(Unknown Source)
2023-09-27T12:11:05.4047032Z at java.base/java.lang.String.getBytes(Unknown Source)
2023-09-27T12:11:05.4047184Z at java.base/java.io.UnixFileSystem.getBooleanAttributes0(Native Method)
2023-09-27T12:11:05.4047357Z at java.base/java.io.UnixFileSystem.getBooleanAttributes(Unknown Source)
2023-09-27T12:11:05.4050774Z at java.base/java.io.File.isDirectory(Unknown Source)
2023-09-27T12:11:05.4051061Z at org.sonar.plugins.javascript.bridge.TsConfigProvider$LookupTsConfigProvider.tsconfigs(TsConfigProvider.java:181)
2023-09-27T12:11:05.4051330Z at org.sonar.plugins.javascript.bridge.TsConfigProvider.tsconfigs(TsConfigProvider.java:94)
2023-09-27T12:11:05.4051770Z at org.sonar.plugins.javascript.bridge.TsConfigProvider.getTsConfigs(TsConfigProvider.java:89)
2023-09-27T12:11:05.4051998Z at org.sonar.plugins.javascript.bridge.JsTsSensor.analyzeFiles(JsTsSensor.java:109)
2023-09-27T12:11:05.4052226Z at org.sonar.plugins.javascript.bridge.AbstractBridgeSensor.execute(AbstractBridgeSensor.java:73)
2023-09-27T12:11:05.4055097Z at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:62)
2023-09-27T12:11:05.4055380Z at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:75)
2023-09-27T12:11:05.4055644Z at org.sonar.scanner.sensor.ModuleSensorsExecutor.lambda$execute$1(ModuleSensorsExecutor.java:48)
2023-09-27T12:11:05.4056940Z at org.sonar.scanner.sensor.ModuleSensorsExecutor$$Lambda$1246/0x0000000100ab8440.run(Unknown Source)
2023-09-27T12:11:05.4057300Z at org.sonar.scanner.sensor.ModuleSensorsExecutor.withModuleStrategy(ModuleSensorsExecutor.java:66)
2023-09-27T12:11:05.4057533Z at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:48)
2023-09-27T12:11:05.4057841Z at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:64)
2023-09-27T12:11:05.4058627Z at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
2023-09-27T12:11:05.4058921Z at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
2023-09-27T12:11:05.4059158Z at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:163)
2023-09-27T12:11:05.4059371Z at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:159)
2023-09-27T12:11:05.4059599Z at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:130)
2023-09-27T12:11:05.4059818Z at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
2023-09-27T12:11:05.4060028Z at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
2023-09-27T12:11:05.4060341Z at org.sonar.scanner.bootstrap.ScannerContainer.doAfterStart(ScannerContainer.java:396)
2023-09-27T12:11:05.4060557Z at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
2023-09-27T12:11:05.4064921Z at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
2023-09-27T12:11:05.4065130Z at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:127)
2023-09-27T12:11:05.4065354Z at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
2023-09-27T12:11:05.4065565Z at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
2023-09-27T12:11:05.4065864Z at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:57)
2023-09-27T12:11:08.2308770Z ##[error]Bash exited with code ‘1’.
2023-09-27T12:11:08.2718355Z ##[section]Finishing: Build image
Even if I tried to set up proper env variables to increase memory (see above) I’ve got the same Java heap space error.
I’ve also configured sonar.exculusions property inside sonar-project.proporties file with the extensions which I don’t needed for analyze.