Quality Gate with Sonar CLI on Bitbucket?

Hi all,

I’m setting up the pipelines to build and scan a C++ project. I’ve reached the point where I can successfully build, scan and submit it, but I’m now only missing the Quality Gate.

The build runs on Bitbucket (Cloud) Pipelines, using a custom Docker image.

I’ve set it up successfully before on a Python project, as I used the pipes for both analysing and quality-gate-ing. As this is a C++ project, I had to run sonar-scanner via CLI inside the build container I created.

This is the step I’m using:

        name: Build and scan Video pipeline
        image: nicovillanueva/pipelinesbuild
        script:
          - cd videopipeline/
          - cmake [...] .
          - /usr/bin/build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir wrapper_output_dir make clean all
          - sonar-scanner
          - pipe: sonarsource/sonarcloud-quality-gate:0.1.6

The final step “obviously” fails, as it runs on a pipe, whilst the rest doesn’t. The error is:

Quality Gate failed: Could not get scanner report: [Errno 2] No such file or directory: '/opt/atlassian/pipelines/agent/build/.bitbucket/pipelines/generated/pipeline/pipes/sonarsource/sonarcloud-scan/sonarcloud-scan.log'

Any pointers on how I could quality-gate this pipeline?

Thank you!

Hey there.

sonarsource/sonarcloud-quality-gate only works if you are also using sonarsource/sonarcloud-github-action which you can’t use if you’re analyzing C/C++ projects.

You can still add -Dsonar.qualitygate.wait=true to your scanner command to poll for the Quality Gate, and fail the step if the Quality Gate has failed.

That did it! Thanks a lot Colin.

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