Skip to content

Security & secrets: SonarQube

SonarQube commands from the Security & secrets folder.

Index
3 items

SonarQube: Run an analysis with sonar-scanner

Safe

Analyse the current directory and upload results.

sonar-scanner -Dsonar.projectKey=<project-key> -Dsonar.host.url=<sonar-url> -Dsonar.token=$SONAR_TOKEN
What each part does
  1. sonar-scannerthe standalone scanner; also reads sonar-project.properties
  2. -Dsonar.projectKey=<project-key>the project in SonarQube
  3. -Dsonar.host.url=<sonar-url>the SonarQube server
  4. -Dsonar.token=$SONAR_TOKENauth token from an env var
  • #sonarqube
  • #ci
  • #quality

Also known as: sonar scan · code quality

SonarQube: Run an analysis with Maven

Safe

Build, test and analyse a Maven project so coverage is included.

mvn verify sonar:sonar -Dsonar.projectKey=<project-key> -Dsonar.host.url=<sonar-url> -Dsonar.token=$SONAR_TOKEN
What each part does
  1. mvn verifybuild and run tests first (so coverage reports exist)
  2. sonar:sonarrun the SonarScanner for Maven
  3. -Dsonar.projectKey=<project-key>the project in SonarQube
  4. -Dsonar.host.url=<sonar-url>the SonarQube server
  5. -Dsonar.token=$SONAR_TOKENauth token from an env var
  • #sonarqube
  • #ci
  • #quality

Also known as: sonar maven

SonarQube: Check the quality gate status

Safe

OK or ERROR for the latest analysis. Add -Dsonar.qualitygate.wait=true to the scanner to block CI instead.

curl -s -u "$SONAR_TOKEN:" "<sonar-url>/api/qualitygates/project_status?projectKey=<project-key>" | jq -r .projectStatus.status
What each part does
  1. curl -sHTTP request, quiet
  2. -u "$SONAR_TOKEN:"token as the user name, empty password
  3. /api/qualitygates/project_status?projectKey=<project-key>quality gate result for the project
  4. | jq -r .projectStatus.statusprint just OK, WARN, ERROR or NONE

Also known as: quality gate failed · sonar gate

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…