Error during SonarScanner execution - can't start scanner with build-wrapper-dump.json

Hello!
I have a similar problem described here: Can not run program with build-wrapper-dump.json
But since there was no solution posted I have to request for help of experts.

Versions:
SonarQube Server version: 8.5.1.38104
build-wrapper version: 6.13 (linux-x86)
SonarScanner version: 4.5.0.2216
CFamily plugin version: 6.13.0.22261

What am I trying to achieve:
We have a c++ project that is build via special building docker in GitLab CI/CD (docker image is declared at the very beginning of pipeline, so all stages are running inside this docker).
We need to add a stage for launching sonar-scanner.
Compiled code is declared as “artifacts” that exist only in docker and then they are deploying on the test server in the end of pipeline.

What have I tried so far to achieve this:

  1. We have added sonar-scanner and build-wrapper into building docker as executable binaries.

  2. We have modified our “make” JOB with build-wrapper and have pointed output folder with headers on the “build” stage. Output folder is declared as “artifact” at the end of “build” stage.

  3. We have added additional stage with launching sonnar-scanner. Output folder of build-wrapper from “build” stage is mounted as artifact to this new stage.

  4. During execution of sonnar-scanner we get this error:

INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 28.333s
INFO: Final Memory: 115M/560M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarScanner execution
java.lang.IllegalStateException: java.io.IOException: Cannot run program "/myproject_build_path/.scannerwork/.sonartmp/13627636375248796021/subprocess" (in directory "/myproject_build_path/build/myapp/some_file_from_build-wrapper-dump.json"): error=2, No such file or directory
	at com.sonar.cpp.driver.ProcessExecutor.execute(ProcessExecutor.java:68)
	at com.sonar.cpp.driver.ProcessExecutor.execute(ProcessExecutor.java:44)
	at com.sonar.cpp.analyzer.ClangDriver.lambda$probeCompiler$10(ClangDriver.java:555)
	at java.base/java.util.HashMap.computeIfAbsent(Unknown Source)
	at com.sonar.cpp.analyzer.ClangDriver.probeCompiler(ClangDriver.java:553)
	at com.sonar.cpp.analyzer.ClangDriver.onCapture(ClangDriver.java:333)
	at com.sonar.cpp.plugin.CFamilySensor.process(CFamilySensor.java:492)
	at com.sonar.cpp.plugin.CFamilySensor.execute(CFamilySensor.java:339)
...

Here is how our .gitlab-ci.yml looks like:

image: custom-registry/build-docker

stages:
- build
- sonarqube-check

build-job:
  script:
    - mkdir -p build/myapp
    - cd build/myapp
    - cmake /myproject_build_path/my_app
    - export PATH=$PATH:/opt/build-wrapper-linux-x86
    - build-wrapper-linux-x86-64 --out-dir build_wrapper_output_my_built_app -j4
  artifacts:
    paths:
      - build/myapp/my_built_app
      - build/myapp/build_wrapper_output_my_built_app/
  stage: build
  only:
    - master
    - simulcast

sonarqube-check:
  artifacts:
    paths:
      - build/myapp/build_wrapper_output_my_built_app/
  script:
    - export PATH=$PATH:/opt/sonar-scanner-4.5.0.2216-linux/bin
    - sonar-scanner -Dsonar.qualitygate.wait=true -Dsonar.login=XXXXXXXXXX -Dsonar.host.url=http://my.sonarqube.server:9000/ -Dsonar.cfamily.build-wrapper-output=build/myapp/build_wrapper_output_my_built_app -Dsonar-project.properties=sonarqube-git-analysis
  allow_failure: true
  stage: sonarqube-check
  only:
    - master
    - simulcast

It seems that scanner can’t find specific file that he had gained on the build stage from build-wrapper-dump.json.
I think that problem is that artifacts doesn’t exist in repo with sources. They exist only during building stage.

Any help will be appreciated. Thanks in advance.

Hi @Mike_F,

it is quite strange failure.

this file is uncompressed during sonar-scanner. Does this happen systematically at every run? If it is the case I wonder whether the cfamily jar file in the server is corrupted.

Hi!
Error occurs every time.
As for corrupted cfamily jar file I can say, that we are able to successfully scan “Hello world” cpp project without any errors.

UPDATE: I have clarified information from our developers. Some files that are listed in build-wrapper-dump.json exist only in docker and they don’t transfer to another stages.

As far as I understand there can be only two solutions:

  1. Declare those files as artifacts and transfer them to sonarqube-check stage
  2. Start a scanner directly in build stage

Both options seems to be complicated…
1 - we have to add unnecessary files (for running app) to artifacts. And there are a lot of such files.

2 - we have to make sonar-scanner as a stopper for the whole pipeline…

The idea was to minimize influence on the current pipeline…

Issue solved by declaring

/myproject_build_path/build/myapp/

path as an artifact on a build stage.

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