Skip to main content
Cloud DevOps Solutions
Get a quote Talk to an engineer

DevSecOps and secrets

SonarQube Consulting: Code Quality and Security Analysis Teams Actually Use

SonarQube is a static analysis platform that scans source code for bugs, code smells, security hotspots and vulnerabilities, tracks coverage and duplication, and enforces quality gates. We deploy and integrate it with CI, tune rules to your languages and apply gates to new code so developers are not buried in legacy findings.

Key takeaways

  • SonarQube analyses your own source code. It complements dependency and image scanners rather than replacing them.
  • The Clean as You Code approach applies the gate to new and changed code, which makes adoption possible on a large, imperfect codebase.
  • Self-hosting means a database, JVM tuning, backups and upgrades. SonarQube Cloud removes that work at the cost of sending code analysis to a vendor.
  • Coverage and rule counts are weak goals. A small agreed gate, enforced consistently, beats a long list nobody trusts.
  • Static analysis produces false positives and misses design flaws. Treat findings as input to review, not a verdict.

What teams use SonarQube for

Pull request quality gates

Every pull request is analysed and decorated with issues on the changed lines, and merging is blocked only when the agreed gate fails.

Security hotspot review

Code that touches crypto, authentication, deserialisation or input handling is flagged for human review, with a workflow to mark each one safe or fix it.

Legacy codebase improvement

A new code period isolates fresh work from old debt, so standards rise steadily without a stop-the-world clean up.

Coverage and duplication tracking

Teams see test coverage on new code and duplicated blocks, which helps target refactoring and testing effort.

Portfolio visibility for engineering leads

Project and portfolio views show where risk and maintainability debt are concentrated across many repositories.

What SonarQube is and why teams adopt it

SonarQube reads your source code without running it and reports problems it can recognise from patterns and data flow: likely bugs, risky constructs, security vulnerabilities, duplicated code and low test coverage. It supports many mainstream languages and presents results per project, per branch and per pull request.

Teams adopt it for two reasons. Engineering leads want a consistent standard that does not rely on every reviewer remembering everything. Security and compliance owners want evidence that code is analysed before release. Both are legitimate, and both fail if the rollout floods developers with thousands of old findings. As SonarQube consulting engineers, we spend most of our effort on gate design and tuning, not installation.

How we run SonarQube in production

Hosting choices

The self-managed server is a Java application backed by PostgreSQL, with search indexing that is sensitive to disk speed and memory. It is straightforward on a single well-sized VM or in Kubernetes with the official Helm chart, but it is stateful: you need an external database, regular backups, TLS, and a plan for upgrades between versions. The vendor’s cloud offering removes this burden. We help you decide using data residency, network access to your Git provider and who would be on call for the server.

CI integration

The scanner runs in your pipeline and uploads results. For a Maven or generic project, the call is short:

sonar-scanner \
  -Dsonar.projectKey=payments-api \
  -Dsonar.sources=src \
  -Dsonar.tests=test \
  -Dsonar.host.url="$SONAR_HOST_URL" \
  -Dsonar.token="$SONAR_TOKEN" \
  -Dsonar.qualitygate.wait=true

With sonar.qualitygate.wait the job fails when the gate fails, so the pull request status reflects it. The token comes from your secrets store, ideally something like HashiCorp Vault rather than a shared repository variable. Our CI/CD pipeline service and GitHub Actions page cover caching and parallel stages so analysis does not dominate build time. Shallow clones can break blame information and new code detection, so the pipeline fetches enough history.

Authentication and access

We connect SonarQube to your single sign-on, map groups to project permissions, and restrict who may change quality profiles or mark issues as accepted. Scanner tokens are scoped per project or per pipeline and rotated.

Rolling out without blocking developers

  1. Report only. Run analysis on every pull request with no failing status for a few weeks. Developers see issues on their own changes and get used to them.
  2. Measure the noise. Count which rules produce the most issues and the most dismissals. These are the candidates for tuning.
  3. Gate on new code. Enable a failing gate for new code only: no new blocker or critical issues, no new unreviewed security hotspots, a coverage threshold you already meet.
  4. Raise slowly. Increase thresholds one at a time, and only when the team consistently clears the current ones.
  5. Burn down legacy separately. Legacy findings get a time-boxed backlog owned by teams, not a merge blocker.

Tuning rules and findings

A default quality profile covers every rule the vendor ships, which is not the same as every rule that matters to you. We copy the default profile, disable rules that conflict with house style or frameworks, and lower severity for rules that are advisory. Generated code, vendored libraries and migrations are excluded. Security hotspots are different from vulnerabilities: they are code that needs a human judgement, so we define who reviews them and how fast.

Coverage targets deserve care. A high coverage number on new code is a reasonable guide, but chasing a percentage encourages tests that execute lines without asserting anything. We prefer a modest gate paired with review of what is actually tested.

Cost, capacity and day-2 operations

Cost has two parts: licensing, which depends on edition and lines of code analysed, and the operational cost of running the server. Check the current pricing model with the vendor rather than relying on assumptions. Operationally, we monitor database size, background task queues and disk, back up the database before upgrades, and follow the long-term support release unless you need a newer feature. Upgrades can reindex projects and take a while on large instances, so they are scheduled out of hours.

Failure modes we see

The usual failures are organisational. A gate is switched on for the whole codebase and promptly disabled after a week of blocked merges. Rules are left at defaults so reviewers see hundreds of style comments and stop reading them. Or the server is installed by one engineer who then leaves, and upgrades stall until the version is unsupported. We design around each of these: new-code gates, a short curated rule set, and a named owner with a documented runbook.

Honest limits

SonarQube is pattern and data-flow based. It does not understand your business logic, cannot detect most authorisation mistakes, and misses vulnerabilities that depend on runtime configuration. Some rules produce false positives, and some real issues need paid editions for deeper security analysis, so check what your edition includes before planning around it. It does not scan dependencies or images, which is what Trivy is for, and it does not read your Terraform, where Checkov is stronger. Treat a green gate as “no known problems of these kinds in the changed lines”, not “secure”.

When to choose something else

On GitHub with a security focus, CodeQL or Semgrep may give better security signal with less to operate. For a small team with one language, linters in CI are often enough. If your main concern is dependencies, start with a software composition tool.

Working with us

We typically deliver a pilot on two or three repositories, agree the gate with engineering leads, then roll out team by team. If you also need pipeline design, see our Azure DevOps consulting and managed DevOps services, or book a consultation.

Official documentation: www.sonarsource.com/products/sonarqube

How we work with SonarQube

  1. 01

    Choose the edition and hosting

    We compare self-managed and cloud options against your languages, branch analysis needs, data residency and operating capacity.

  2. 02

    Deploy and secure the server

    For self-hosting we set up the application, an external PostgreSQL database, TLS, single sign-on, backups and resource sizing.

  3. 03

    Integrate with CI and pull requests

    Scanners run in your pipeline with sensible caching, and results decorate pull requests in GitHub, GitLab or Azure DevOps.

  4. 04

    Define the quality gate

    We start from a gate on new code covering reliability, security, coverage and duplication, and set thresholds you can meet today.

  5. 05

    Tune the rule set

    Quality profiles are trimmed to relevant rules, noisy checks are adjusted or disabled with reasons, and generated code is excluded.

  6. 06

    Enforce gradually and train

    The gate runs in report-only mode first, then becomes blocking. Developers get guidance on handling hotspots and false positives.

SonarQube compared with the alternatives

We recommend the tool that fits your team, not the one we know best. Here is when each option makes sense.

OptionChoose it when
SonarQubeSonarQube is a static analysis platform that scans source code for bugs, code smells, security hotspots and vulnerabilities, tracks coverage and duplication, and enforces quality gates.
GitHub Advanced Security (CodeQL)Choose it if you are on GitHub and want deep semantic security queries integrated with code scanning and no server to run. It focuses more on security than maintainability.
SemgrepChoose it if you want fast, readable custom rules and a security-first workflow, and your team is willing to write rules for its own patterns.
Snyk CodeChoose it if you already use Snyk for dependencies and want one commercial platform with IDE fixes, accepting the licensing cost.
Language linters and compilersChoose them alone for small teams with a single language, where ESLint, golangci-lint or similar in CI gives most of the value with no extra system.

Tools we use alongside SonarQube

GitHub ActionsGitLab CIAzure DevOpsJenkinsPostgreSQLSonarScannerSonarLintJaCoCoIstanbulKubernetesHelmTrivySemgrepOWASP Dependency-Check

Frequently asked questions

What is SonarQube used for?
SonarQube is used to analyse source code automatically for bugs, maintainability problems, security vulnerabilities and security hotspots, and to track test coverage and duplication over time. Teams wire it into pull requests so issues appear on the lines that changed, and use quality gates to decide whether a change meets agreed standards.
What is a quality gate?
A quality gate is a set of conditions a project must meet, such as no new blocker issues, a minimum coverage on new code and limited duplication. If the conditions fail, the analysis is marked failed and CI can block the merge. Applying the gate to new code keeps it achievable on older projects.
How do we adopt SonarQube on a legacy codebase?
Use the new code approach. Leave existing issues visible but non-blocking, and fail only on problems introduced by recent changes. Start in report-only mode, fix the most severe existing issues over time, and raise thresholds gradually. Demanding a clean legacy codebase on day one usually ends with the gate being disabled.
Should we self-host SonarQube or use the cloud version?
Use the cloud version if you want no infrastructure to maintain and are comfortable with the vendor analysing your code metadata. Self-host if you need data to stay in your environment or have unusual network constraints. Self-hosting needs a database, backups, upgrades and capacity planning, which is real ongoing work.
How do you handle false positives?
Mark them as false positive or accepted with a short reason in the interface, adjust or disable rules that do not suit your code in a quality profile, and exclude generated files from analysis. Track the rate of such decisions. If a rule is marked false almost every time, it is costing more attention than it returns.
Does SonarQube replace dependency and container scanning?
No. SonarQube analyses code you wrote. Vulnerable libraries and base image packages need a tool such as Trivy, and infrastructure files need an IaC scanner. Each layer finds a different class of problem, and together they cover far more than any one tool.

Talk to an engineer about SonarQube

Book a free 30-minute call. We review your current setup and tell you honestly whether and how we can help.

Written by Saddique Khan, DevOps / SRE / Cloud Consultant Engineer. Last updated 2026-10-09.