Introduction Code quality gates in CI/CD pipelines enforce standards before code can be merged or deployed. When quality gates fail, it indicates code quality issues that must be addressed before the pipeline can proceed.
Symptoms - Pipeline fails: "Quality Gate status: FAILED" - SonarQube shows red gate with specific conditions failed - "Coverage on New Code is less than 80%" - "Security Rating is worse than A" - Pipeline blocks merge despite tests passing
Common Causes - Test coverage dropped below threshold - New code has code smells or bugs - Security hotspots not reviewed - Duplicated code percentage exceeded - Technical debt ratio too high
Step-by-Step Fix 1. **Check SonarQube dashboard for specific failures**: Navigate to the project in SonarQube and review the Quality Gate conditions.
- 1.Run SonarQube analysis locally:
- 2.```bash
- 3.sonar-scanner -Dsonar.host.url=https://sonar.example.com \
- 4.-Dsonar.token=<token>
- 5.
` - 6.Fix the specific issues:
- 7.- For coverage: Add tests for uncovered code paths
- 8.- For bugs: Fix the identified bugs in SonarQube report
- 9.- For code smells: Refactor the flagged code
- 10.- For security: Review and fix security hotspots
- 11.Adjust quality gate thresholds (if needed):
- 12.In SonarQube: Administration > Quality Gates > Edit conditions