I installed sonarqube in my MAC machine using the docker compose given below.
version: "2"
services:
sonarqube:
image: sonarqube
ports:
- "9000:9000"
networks:
- sonarnet
environment:
- SONARQUBE_JDBC_URL=jdbc:postgresql://db:5432/sonar
volumes:
- sonarqube_conf:/opt/sonarqube/conf
- sonarqube_data:/opt/sonarqube/data
- sonarqube_extensions:/opt/sonarqube/extensions
- sonarqube_bundled-plugins:/opt/sonarqube/lib/bundled-plugins
db:
image: postgres
networks:
- sonarnet
environment:
- POSTGRES_USER=sonar
- POSTGRES_PASSWORD=sonar
volumes:
- postgresql:/var/lib/postgresql
# This needs explicit mapping due to https://github.com/docker-library/postgres/blob/4e48e3228a30763913ece952c611e5e9b95c8759/Dockerfile.template#L52
- postgresql_data:/var/lib/postgresql/data
networks:
sonarnet:
driver: bridge
volumes:
sonarqube_conf:
sonarqube_data:
sonarqube_extensions:
sonarqube_bundled-plugins:
postgresql:
postgresql_data:
After which I used the command
sonar-scanner
to analyse the project using sonarqube.

The analysis report is shown above. If you notice, the code coverage part is left blank, even though I have written some python unittest scripts. Please suggest a way so that I can get the code coverage report for my python project in sonarqube. Thanks in advance.
SonarQube doesn't calculate a code coverage. It only displays results provided by other tools.
You have to execute a tool which calculates code coverage (e.g. Coverage.py) and next add analysis parameters:
sonar.python.coverage.reportPath - a report path of the unit test resultssonar.python.coverage.itReportPath - a report path of the integration test resultsYou can read everything on SonarQube wiki: https://docs.sonarqube.org/display/PLUG/Python+Coverage+Results+Import
You’ll need a code coverage tool to analyze how much of the project’s code is coverage by unit tests.
As mentioned, one of the tools is coverage.
The coverage tool can be used to generate a SonarQube-compatible XML report, which is then uploaded to SonarQube.
Once installed, run coverage xml.
In your sonar-project.properties add:
sonar.python.coverage.reportPath=coverage.xml
Remember to add the auto-generated coverage output files to .gitignore:
.coverage
coverage.xml
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With