SonarCloud analysis does not works for Python project in BitbucketPipeline

Template for a good new topic, formatted with Markdown:

  • ALM used: Bitbucket Cloud
  • CI system used: Bitbucket Cloud
  • Scanner command used when applicable:
    - pipe: sonarsource/sonarcloud-scan:2.0.0
    - pipe: sonarsource/sonarcloud-quality-gate:0.1.6
  • Languages of the repository: Python
  • Error observed (wrap logs/code around with triple quotes ``` for proper formatting)
INFO: 484/484 source files have been analyzed
INFO: The Python analyzer was able to leverage cached data from previous analyses for 0 out of 484 files. These files were not parsed.
INFO: Sensor Python Sensor [python] (done) | time=19791ms
INFO: Sensor Cobertura Sensor for Python coverage [python]
INFO: Python test coverage
INFO: Parsing report '/opt/atlassian/pipelines/agent/build/coverage-reports/coverage.xml'
WARN: Invalid directory path in 'source' element: /home/*company*
ERROR: Cannot resolve the file path 'conftest.py' of the coverage report, the file does not exist in all 'source'.
ERROR: Cannot resolve 577 file paths, ignoring coverage measures for those files

My step in bitbucket-pipelines looks like this:

    - step: &run-tests-sonarcloud
        name: Run tests
        size: 2x
        caches:
          - docker # adds docker layer caching   # See https://confluence.atlassian.com/bitbucket/caching-dependencies-895552876.html
          - node
          - pip
          - docker-base
          - sonar
        script:
          - *load-docker-base-image-if-exists-in-cache
          - *bla-bla-bla*
          - *save-docker-base-image-if-missing-in-cache
          - mkdir coverage-reports
          - >-
            docker run
            -v $*bla-bla-bla*
            "TEST"
          - >-
            docker run
            *bla-bla-bla*
            -v ${PWD}/coverage-reports:/coverage-reports
            *container-name*
            ./test.sh
          - pipe: sonarsource/sonarcloud-scan:2.0.0
            variables:
              DEBUG: 'false' #DEBUG
          - pipe: sonarsource/sonarcloud-quality-gate:0.1.6
        services:
          - docker
  • Steps to reproduce: I am trying to launch Sonarcloud analysis for my project. But, it seems, that it does not work at all. I see 0 bugs, 0 code smells, 0 vulnerabilities, 0 security hotspots, and 0 coverage. From logs I can see, that Sonar is analyzing the code, and successfully send the results, but I can’t see anything in web Sonar. What am I doing wrong? :slight_smile:
    I’ve checked sonar-project.properties file, and it looks good:
sonar.projectKey=*bla-bla-bla*
sonar.sources=/src
sonar.exclusions=src/*bla-bla-bla*/tests
sonar.python.version=3.9
sonar.python.coverage.reportPaths=/coverage-reports/coverage.xml

My files structure on bitbucket instance looks like this:
In the . we have:

src/(sources)
coverage-reports/coverage.xml
sonar-project.properties
  • Potential workaround

Do not share screenshots of logs – share the text itself (bonus points for being well-formatted)!

Hi,

Welcome to the community!

The analysis log snippet you’ve provided shows a problem with your coverage reports which is unrelated to the number of issues detected.

If you check the Measures tab of the branch in question (main, I guess?), and expand “Size”, is Lines of Code a non-zero number?

And can you provide your full analysis log?

anal

The analysis / scanner log is what’s output from the analysis command. Hopefully, the log you provide - redacted as necessary - will include that command as well.

This guide will help you find them.

 
Ann