SonarQube Server version: 9.9.8.100196 (company instance)
SonarScanner CLI version: 7.1.0.4889
How is SonarQube deployed: Company-managed instance (not self-hosted, details unknown)
Project type:
Symfony PHP project
What are you trying to achieve:
I want my GitLab CI pipeline to fail if the unit test coverage is below the threshold defined by the Quality Gate (“Sonar way” with coverage ≥ 80%).
What have you tried so far:
- The project is a Symfony PHP app, coverage is about 44%.
- The pipeline runs PHPUnit with coverage and uploads the clover.xml report.
- The SonarQube analysis imports the report and shows the correct coverage in the UI.
- The Quality Gate used is “Sonar way” (default), which should require at least 80% coverage.
- The pipeline job is configured with
allow_failure: false
andsonar.qualitygate.wait=true
. - Despite this, the pipeline passes even when coverage is below 80%.
Problem
I am surprised that the pipeline does not fail when the coverage is insufficient.
Does anyone know why the Quality Gate is not blocking the pipeline as expected?
sonar-project.properties file :
sonar.projectName=xx
sonar.projectVersion=1.0.0
sonar.projectKey=xx
sonar.sources=src
sonar.tests=tests
sonar.sourceEncoding=UTF-8
sonar.language=php
sonar.exclusions=var/,vendor/,public/build/, assets/, tests/bootstrap.php
sonar.coverage.exclusions=tests/**,src/Kernel.php
sonar.php.coverage.reportPaths=var/coverage/clover.xml
sonar.php.tests.reportPath=var/coverage/junit.xml
sonar.links.scm=https://git.xx.fr/etudes/Symfony/xx/xx.git
sonar.host.url=https://xx.tech.xx.fr
sonar.qualitygate.wait=true
.gitlab-ci :
job uni test
script:
- mkdir -p var/coverage
- XDEBUG_MODE=coverage php vendor/bin/phpunit --coverage-clover var/coverage/clover.xml --coverage-html var/coverage/html --log-junit var/coverage/junit.xml
- cd var/coverage && zip -r coverage-html.zip html/ && cd ../.. || echo “Zip creation failed but continuing”
Job sonarqube :
script:
- ls -la var/coverage/
- sonar-scanner
Thank you for your help!