Unable to import / view pytest code coverage in Sonarqube Version 7.7 (build 23042) when sonar scanner is executed from Jenkins pipeline

When I execute sonar-sccaner from my local system it works well and I can see coverage report on UI
But when same is executed form Jenkins it does not show coverage report:

Following command I am executing from local machine and from Jenkins pipeline:
sonar-scanner -Dsonar.projectKey=XXXXXX -Dsonar.python.xunit.reportPath=‘build_results/testresults.xml’ -Dsonar.python.pylint.reportPath=pylint-report.txt -Dsonar.python.coverage.reportPaths=‘build_results/coverage.xml’

Following is log line from local
16:08:14.019 DEBUG: Using pattern ‘build_results/coverage.xml’ to find reports
16:08:15.314 INFO: Python test coverage
16:08:15.316 INFO: Parsing report ‘/Users/falak.shah/xxxx/xxxx/xxxxx/build_results/coverage.xml’

Following is log line from Jenkins server
16:32:37.850 INFO: Sensor Python Squid Sensor [python] (done) | time=10477ms
16:32:37.851 INFO: Sensor Cobertura Sensor for Python coverage [python]
16:32:37.852 DEBUG: Using pattern ‘build_results/coverage.xml’ to find reports
16:32:38.234 WARN: No report was found for sonar.python.coverage.reportPaths using pattern build_results/coverage.xml
16:32:38.234 INFO: Sensor Cobertura Sensor for Python coverage [python] (done) | time=383ms
16:32:38.234 INFO: Sensor PythonXUnitSensor [python]
16:32:38.235 DEBUG: Using pattern ‘build_results/testresults.xml’ to find reports
16:32:38.455 INFO: Processing report ‘/Users/Shared/Jenkins/Home/workspace/test/build_results/testresults.xml’

You can see that it is able to parse unit test result file successfully but giving error for coverage.xml

Note: Using SonarQube - Community Edition Version 7.7 (build 23042)

It looks like there’s no file named build_results/coverage.xml in the workspace of the Jenkins project.
Can you check whether it’s present at the time of the SonarQube analysis?

build_results/coverage.xml do present in jenkins workspace directory. I tried putting coverage.xml inside root directory of jenkins project workspace. But still it didn’t work.

But some how when I used snoar-project.properties and put sonar.python.coverage.reportPaths inside that, coverage report is parsed successfully and could see coverage detail on UI

I’m not able to reproduce a difference of behavior when using sonar-project.properties compared to using command line arguments.

Please note that there are 2 different properties (see documentation):

  • sonar.python.coverage.reportPath which is now deprecated
  • sonar.python.coverage.reportPaths

Both should work as long as you don’t use both at the same time.

Do you still need help, or is your problem solved?

For now my issue is solved using sonar-project properties