What are required to do a sonar-scan with the existing build-wrapper-dump.json?

Hi Experts,

We are building our product in docker and we wrapped the build.sh with the correct build-wrapper from sonarqube official.
We want to split the build and scan in two different steps but still using the same docker image. To elaborate the details:

  1. We are using a docker image to build the product code, assume it’s called tools/builder.
  2. We wraps the build.sh with the correct build-wrapper.
  3. Kick off a build in docker container using “tools/builder” - source dir: /usr/src, build-wrapper-outputs: /wp-outputs. These directories are existing on the host.
  4. Execute the scan in another docker container but using the same image “tools/builder”, mounting the source dir and build-wrapper outputs with the same structure as in the build container. The container is executed on the same host as the build container.

However, this is not working. I’ve got the following error:

ERROR: Error during SonarQube Scanner execution
java.lang.IllegalStateException: The “build-wrapper-dump.json” file was found but 0 C/C++/Objective-C files were analyzed. Please make sure that:
* you are using the latest version of the build-wrapper and the SonarCFamily analyzer
* you are correctly invoking the scanner with correct configuration * your compiler is supported
* you are wrapping your build correctly
* you are wrapping a full/clean build
* you are providing the path to the correct build-wrapper output directory

Could you tell me what else does sonar-scanner needs to perform a successful analysis with the existing build-wrapper-dump.json?
Will environment variables in the docker containers also count?
Must the build and the scan be performed in the same docker container even if they are using the same image and same mounted volumes?

We are using sonarqube server: 7.9.1 LTS
Scanner cli: 4.0.0.1744

Hi @Kevin_Young,

Is build-wrapper running inside or outside the container? build-wrapper follows processes creation which means that it should wrap the build inside the docker container.
In short the following doesn’t work:

build-wrapper --out-dir out docker exec -ti container -v ... bash build.sh

Instead it should be something like:

docker exec -ti container -v ... build-wrapper --out-dir out bash build.sh

If you use the same docker image and the paths do not change between the two then you can do it in two steps.

@mpaladin Thank you for your quick response. I resolved the issue already. And I did not use the same image as the build. Instead, I used sonarsource/sonar-scanner-cli and mounted the directories as the same as in the build container. The scan was successful.
BTW, do you have a doc for build-wrapper-dump.json, like what’s in it, how it’s being used for analysis?

Hi @Kevin_Young,

Actually, I am not sure you got a good analysis result, it is likely that a lot of system headers were not found on the the sonarsource/sonar-scanner-cli docker image. You can verify that by setting sonar.verbose=true property, I am almost sure you are getting a lot of file not found errors. Could you please check that?

Thank you for this information. I’ve turned on the TRACE logs of the analysis. I’m checking on the logs again. Just too many source files.

Hi @Kevin_Young,

no need for TRACE, we print not found headers in DEBUG mode.