SonarQube provides automated code quality and security analysis across every build. The Jenkins pipeline submits analysis results to SonarQube after the build and test stages usingDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/infra-neo/CICD/llms.txt
Use this file to discover all available pages before exploring further.
mvn sonar:sonar, and a dedicated Quality Gate stage blocks deployment if the code fails the configured quality thresholds. This means a build with too many bugs, security vulnerabilities, or insufficient test coverage will never make it to Nexus or the application servers.
Quick Reference
| Property | Value |
|---|---|
| Port | 9000 |
| Image | sonarqube:community |
| Container Name | sonarqube |
| Default Credentials | admin / admin |
| Database | PostgreSQL 13 (postgres container) |
| Data Volume | sonarqube_data |
| Extensions Volume | sonarqube_extensions |
| Logs Volume | sonarqube_logs |
Quality Gate Integration
The pipeline integrates with SonarQube through two Jenkinsfile stages. First, the SonarQube Analysis stage runs Maven inside awithSonarQubeEnv block, which injects the server URL and authentication token automatically. Second, the Quality Gate stage polls SonarQube and aborts the pipeline if analysis results do not pass.
waitForQualityGate abortPipeline: true call pauses the build for up to five minutes, polling the SonarQube webhook. If the Quality Gate returns ERROR, the pipeline is immediately aborted and the deployment stages are skipped. The SonarQube server name 'SonarQube' must match the name registered in Jenkins by 04-configure-sonarqube.groovy.
Analysis Capabilities
Code Quality
Detects bugs, code smells, and duplicated blocks. Measures cyclomatic complexity and provides per-file and per-module breakdowns.
Security Vulnerabilities
Identifies OWASP Top 10 vulnerabilities, injection flaws, and insecure API usage using built-in security rules and optional security packs.
Test Coverage
Integrates with JaCoCo and other coverage tools to enforce minimum line and branch coverage thresholds as part of the Quality Gate.
Technical Debt
Calculates remediation effort in hours for all issues and tracks debt ratio over time, helping teams prioritize refactoring work.
Database Configuration
SonarQube requires a relational database for its data store. The stack uses a dedicated PostgreSQL 13 container with the following connection settings defined indocker-compose.yml:
docker-compose.override.yml (see docker-compose.override.yml.example) and override the environment variables there rather than editing the base docker-compose.yml directly:
Memory Tuning
SonarQube runs two JVM processes internally: the Web Server and the Compute Engine (CE). Each has its own JVM options. The override example configures them for production-grade workloads:vm.max_map_count Requirement
Troubleshooting
SonarQube won't start or keeps restarting
SonarQube won't start or keeps restarting
The most common cause is Apply the fix:Then restart the container:If the crash is unrelated to
vm.max_map_count being too low. Check the container logs for an Elasticsearch bootstrap error:vm.max_map_count, check whether PostgreSQL is healthy — SonarQube depends on the postgres container being fully ready before it can initialize.Database connection failed — 'Could not connect to database'
Database connection failed — 'Could not connect to database'
- Verify that the
postgrescontainer is running and accepting connections: - Confirm that
SONAR_JDBC_USERNAMEandSONAR_JDBC_PASSWORDin thesonarqubeservice exactly matchPOSTGRES_USERandPOSTGRES_PASSWORDin thepostgresservice. - If the credentials were changed after the database was initialized, the database user will need to be updated separately inside PostgreSQL. The simplest recovery path is to drop and recreate the database:
Can't login — admin/admin credentials rejected
Can't login — admin/admin credentials rejected
SonarQube requires you to change the default password on first login. Navigate to
http://localhost:9000, log in with admin/admin, and you will be immediately prompted to set a new password. After changing it, update the sonarqube-token credential in Jenkins:- Go to Jenkins → Manage Jenkins → Credentials.
- Find the
sonarqube-tokensecret text credential. - Update the secret value to match the new SonarQube token or password.
SonarQube analysis fails in the pipeline
SonarQube analysis fails in the pipeline
- Verify the
sonarqube-tokencredential exists in Jenkins: - Confirm SonarQube is reachable from within the Jenkins container:
A healthy response looks like
{"id":"...","version":"...","status":"UP"}. - Run a manual analysis to isolate the problem:
- Check that the SonarQube server name in
04-configure-sonarqube.groovy("SonarQube") matches the name used inwithSonarQubeEnv('SonarQube')in the Jenkinsfile.
