Sonarqube can't find coverage file

We deploy our pipelines with Jenkins and we just started introducing SonarQube to one of its steps. For one of our full stack projects, we want to report the coverage only for the python backend folder. However, SonarQube keeps raising…

WARN: No report was found for sonar.python.coverage.reportPaths using pattern /tmp/coverage/coverage.xml

Even though, in the tests steps, I can see the following…

Coverage XML written to file /tmp/coverage/coverage.xml

As a result, the project appears with 0% coverage in SonarQuebe dashboard.

I tried setting sonar.verbose=true but I didn’t find any valuable information. The only thing I could thought was that sonar.python.coverage.reportPaths can’t handle absolute paths - but it doesn’t make any sense to me. Does somebody have a clue?

Additional info:

  • The test step command is something like cd /opt/project/backend && HOME=/tmp PYTHONPATH=../ COVERAGE_FILE=/tmp/coverage/.coverage pytest --cov=. --cov-report=xml:/tmp/coverage/coverage.xml -s tests/unit
  • I have the following in my sonar-project.properties file (in the root folder):
    • sonar.sources=backend
    • sonar.exclusions=terraform/**/plan.json,**/*.test.*
    • sonar.coverage.exclusions=tests/*,tests_ml_engine/*
    • sonar.sourceEncoding=UTF-8
    • sonar.test=backend
    • sonar.test.inclusions= backend/tests/unit/*
    • sonar.python.coverage.reportPaths=/tmp/coverage/coverage.xml
  • We are deploying Sonarqube with Kubernetes

Hey there.

You may want to try running a cat /tmp/coverage/coverage.xml immediately before the scanner is executed, to verify that the file is where you expect it to be.

If that doesn’t help, I’d suggest sharing your full Jenkins pipeline configuration here, alongside logs from your pipeline.

Hi there
Did you manage to solve this - I’m having exactly the same problem

Yeah I had to create the coverage dir manually. I ended up simplifying the command as well. Here’s that part in Jenkinsfile


docker.image(localImage).inside("$parameters") {
    sh "mkdir -p coverage"
    sh "COVERAGE_FILE=coverage/.coverage pytest --cov=backend --cov-report=xml:coverage/coverage.xml -s backend/tests/unit"
    cobertura coberturaReportFile: 'coverage/coverage.xml'
    stash includes: "coverage/**", name: "coverReport"  
}

And then…

stage('SonarQube Analysis') {
    node {
        checkout scm
        unstash 'coverReport'

        def scannerHome = tool 'SonarScanner'
        withSonarQubeEnv() {
             sh "${scannerHome}/bin/sonar-scanner"
         }
    }
}