← All insightsCheat Sheet

SonarQube cheat sheet: the complete command reference

CodeWizard Engineering · 18 October 2025 · 3 min read · Beginner

This is a complete, hands-on SonarQube cheat sheet: install, configure, operate, automate and secure it - with copy-paste commands grouped by task. Bookmark it for day-to-day work, incidents and interviews alike.

SonarQube statically analyzes code for bugs, vulnerabilities, security hotspots and 'code smells', and enforces a Quality Gate in CI so problematic changes fail the build.

Why you reach for it

  • Catches bugs and vulnerabilities before review
  • Quality Gates enforce a consistent bar across teams
  • Tracks tech-debt and coverage trends over time

Installation

bash
docker run -d --name sonarqube -p 9000:9000 sonarqube:community
# open http://localhost:9000 (admin/admin)

Configuration reference

Project configuration file.

properties
# sonar-project.properties
sonar.projectKey=acme-web
sonar.sources=src
sonar.tests=test
sonar.javascript.lcov.reportPaths=coverage/lcov.info
sonar.qualitygate.wait=true

Core commands you use daily

bash
sonar-scanner -Dsonar.host.url=http://localhost:9000 -Dsonar.token=$SONAR_TOKEN

Scan & gate

bash
sonar-scanner \
  -Dsonar.projectKey=acme-web \
  -Dsonar.sources=src \
  -Dsonar.host.url=http://localhost:9000 \
  -Dsonar.token=$SONAR_TOKEN \
  -Dsonar.qualitygate.wait=true

Quality Gate via API

bash
curl -s -u $SONAR_TOKEN: \
  "http://localhost:9000/api/qualitygates/project_status?projectKey=acme-web" | jq .projectStatus.status

Use it in CI/CD

Scan and fail on the Quality Gate.

yaml
- uses: sonarsource/sonarqube-scan-action@v3
  env:
    SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
    SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
- uses: sonarsource/sonarqube-quality-gate-action@v1

Best-practice checklist

  • Enforce a 'new code' Quality Gate on every PR
  • Wire coverage reports into the scan
  • Triage security hotspots, don't blanket-ignore them

Common pitfalls to avoid

  • Analyzing but not enforcing the Quality Gate, so nothing improves
  • Chasing a green gate by disabling rules instead of fixing issues
  • No coverage report wired in, so coverage looks like zero

Security quick wins

  • Treat vulnerabilities and hotspots as gating, not advisory
  • Keep tokens scoped and rotate them

Works well with

  • Trivy - A fast, all-in-one scanner for container images, filesystems, IaC and Kubernetes.
  • GitHub Actions - CI/CD built into GitHub - event-driven workflows defined in YAML, with a huge marketplace of actions.
  • GitLab CI/CD - Pipelines-as-code baked into GitLab, with built-in registry, environments and security scanning.
A cheat sheet is muscle memory on paper - keep it close until the commands live in your fingers.

Want senior help putting SonarQube to work - or a team bootcamp on it? CodeWizard runs Israel's largest DevOps community and embeds named senior engineers with a transparent hours log. Book a free consult or explore the Academy.

Like where this is going?

Get hands-on help from the engineers who write these posts.

Book a free consult