Version note: references describe SonarQube Server 2025.2 behaviour. Check your server, scanner and edition requirements. These examples were not run against a live SonarQube server.
What this guide covers
SonarQube checks source code for issues such as bugs and security problems. A scanner reads your project and sends a report to the SonarQube server. This guide uses the command-line scanner for a simple project.
Before you start
You need a working SonarQube server, an installed SonarScanner CLI, and a project with src and test directories. Java and .NET projects should use their build-specific scanners instead. Run commands from the project root.
Step 1: Create a project
In SonarQube, create a local project and copy its project key. The key identifies the project; it is not a password. Create sonar-project.properties in the repository root:
sonar.projectKey=payments-service
sonar.projectName=Payments service
sonar.sources=src
sonar.tests=test
sonar.sourceEncoding=UTF-8
Replace the key and name with your own. Set the source and test paths to directories that actually exist.
Step 2: Set the server URL and token
Create a project analysis token in SonarQube. In a Bash terminal, enter the server URL and token without putting the token in the repository:
read -r -p "SonarQube URL: " SONAR_HOST_URL
read -r -s -p "Analysis token: " SONAR_TOKEN
printf "\n"
export SONAR_HOST_URL SONAR_TOKEN
The scanner reads these environment variables. In a pipeline, supply them through its secret settings.
Step 3: Run the scan
Check the directories and scanner version, then run the analysis:
set -eu
git rev-parse HEAD
sonar-scanner --version
test -d src
test -d test
test -f sonar-project.properties
sonar-scanner -Dsonar.qualitygate.wait=true -Dsonar.qualitygate.timeout=300
The wait option keeps the command running until SonarQube returns a quality-gate result, or the five-minute timeout expires. A quality gate is the set of checks that decides whether the analysis passes.
Step 4: Open the result
Open the project URL printed by the scanner. Confirm that the latest analysis belongs to your project and commit. Review the issues and quality-gate conditions. An uploaded report can still fail during server processing. If the command fails, read its error before rerunning it.
Check the result
The project should show a completed analysis and a quality-gate result. Fix one reported issue, run the scan again, and check the new result. Keep the token out of logs and delete it when it is no longer needed.
Conversation
0 commentsNo comments yet. Start the conversation below.