Cloudogu EcoSystem Docs
Software version

Easier scanning with Sonar-scanner-cli

Due to common certificate errors, it is not that easy to use the sonar scanner in a local system with self-signed certificates.

SonarQube scan without pipeline tools

To avoid installing a whole stack of SCM Manager, Jenkins, etc., it is easier to modify a Sonar scanner with your own certificate:

  1. Generate a SonarQube token, e.g. at https://example.invalid/sonar/account/security
    • In this example: sqa_3ffb7e36dee85c27ab1b3cca58e0dea400068f70
  2. Select the codebase to be scanned
    • See below for a minimal example
  3. Copy the certificate into a file and store it in the codebase file system
    • CES VM: etcdctl get /config/_global/certificate/server.crt > /vagrant/ces.pem
  4. Copy the certificate into the codebase directory
  5. From the codebase directory ($PWD -> /usr/src/)
    1. start Sonar scanner,
    2. import the certificate, and
    3. scan
    4. scan a second time for good measure, because SonarQube is weird and hates first scans
docker run \
    --rm -u 0 \
    -e SONAR_HOST_URL="https://example.invalid/sonar" \
    -e SONAR_TOKEN="sqa_3ffb7e36dee85c27ab1b3cca58e0dea400068f70" \
    -v "${PWD}:/usr/src" -it --entrypoint sh \
    sonarsource/sonar-scanner-cli

# You will be taken to a shell. Here we continue:
cd /usr/lib/jvm/java-17-openjdk/lib/security
keytool -import -trustcacerts -noprompt -alias sonarqube -file /usr/src/ces.pem -keystore cacerts -storepass changeit
cd -
sonar-scanner
exit # This leaves the container, which is now being deleted. Everything must be repeated for the next scan

Minimal example of a codebase

To find out if and how SonarQube and Sonarcarp work, two or three files are sufficient:

  • go.mod
mkdir test
cd test
go mod init test
  • main.go
package main

import (
	"fmt"
	"path/filepath"
)

func main() {
	a, err := filepath.Abs("asdf") // error here
	fmt.Println("hello world", a)
}
  • sonar-project.properties
sonar.projectKey=test
sonar.sources=.
sonar.exclusions=**/*_test.go,**/vendor/**,**/target/**,**/mocks/**,**/*_mock.go,resources/test/**/index.html,**/mock_**,**/build/make/**
sonar.tests=.
sonar.test.inclusions=**/*_test.go
sonar.test.exclusions=**/vendor/**,**/target/**

Last updated on 8/14/2026