Can't seem to reflect the coverage in Sonarqube analysis on the PR

Tools used: Bitbucket cloud, sonarcloud-scan:1.2.1, Python, python-cov

I can’t seem to make the code coverage results appear in the Code Quality, Quality Gate section of the PR in bitbucket.

  • the coverage report is generated before the scanner runs
  • I used pytest-cov to generate the report which generates the report
  • report generated is of xml format as the documentation required
  • the coverage report generated is valid as I printout the contents during the build
  • I used -Dsonar.python.coverage.reportPaths to somehow force sonar to view the generated report but it still won’t reflect in Quality Gate
  • Still with the reportPaths arg, I tried to put in **/coverage.xml so it won’t matter which folder it is in as long as the name match, but it still won’t work.
  • I also tried generated the report, coverage.xml, to the root and setting this as an arg -Dsonar.python.coverage.reportPaths=coverage.xml but it also still won’t work

Can you please suggest other items that I can check or am I doing something wrong?

Hey there.

  • Are you using SonarQube or SonarCloud? I can’t tell – as you mention SonarQube but filed the thread under SonarCloud.
  • How is your bitbucket-pipelines.yml file configured?
  • What do the logs say? You’ll find logs like the following in the scanner logs:

09:57:19.193 INFO: Sensor Cobertura Sensor for Python coverage [python]
09:57:19.193 DEBUG: Using pattern ‘coverage-reports/coverage-.xml’ to find reports

Hi Colin,

Sorry, I’m still new to this but just to confirm I’m using SonarCloud

Our bitbucket-pipeline is setup as below for SonarCloud.

    sonar: ~/.sonar/cache
  - step: &sonarcloud
      name: SonarCloud
        - sonar
        - pipe: sonarsource/sonarcloud-scan:1.2.1
            SONAR_SCANNER_OPTS: -Xmx1024m
            EXTRA_ARGS: -Dsonar.python.version=3.7

so we have a step that runs the test and generates the coverage report. we use pytest for test execution and coverage report generation.

for the logs, here’s what I get. it does appear that the file is not being scanned for some reason but it is a bit confusing since I’m able to check the file, it exists and I can see the contents of the file.

13:12:18.223 INFO: Sensor Cobertura Sensor for Python coverage [python]
13:12:18.224 DEBUG: Using pattern 'coverage.xml' to find reports
13:12:18.261 WARN: No report was found for sonar.python.coverage.reportPaths using pattern coverage.xml
13:12:18.261 INFO: Sensor Cobertura Sensor for Python coverage [python] (done) | time=38ms

perhaps my pattern is wrong?

I would assume that you aren’t actually sharing the artifact produced in the other step so that it’s accessible to the sonarsource/sonarcloud-scan. For example: if you ran cat coverage.xml before the pipe:

    - cat coverage.xml
    - pipe: sonarsource/sonarcloud-scan:1.2.1

Does anything actually display?

Hi Colin, I tried that command and it caused the build to fail. I guess I’m missing something.

our pipeline looks like this

      - step: *runTests
      - step: *build-test-sonarcloud

I was told that this may not work as these 2 steps are in their own containers.

Is there any chance there is an existing sample bitbucket-pipeline.yml that I can use as a reference to try make it work on my end?