Fakultas Ilmu Komputer UI

Skip to content
Snippets Groups Projects

Sonar Scanner CLI Image

Sonar Scanner CLI bundled in a container image.

Usage

First, you need to have a SonarScanner properties file (e.g. sonar-project.properties) in current working directory. Make sure to avoid putting sensitive information or values that might change over time in the properties file such as SonarQube's authentication token. Those kind of values and configuration can be passed into SonarScanner via CLI prompt.

To run the container image locally using Docker:

docker run -it -v $(pwd):/home/sonar/workspace addianto/sonar-scanner-cli:latest bash
sonar-scanner [sonar-scanner options]

Note: The above example creates a local interactive shell within the running container where you can invoke sonar-scanner with the desired CLI options.

Example:

docker run -it -v $(pwd):/home/sonar/workspace addianto/sonar-scanner-cli:latest bash
sonar-scanner -Dsonar.host.url=https://pmpl.cs.ui.ac.id/sonarqube -Dsonar.login=[YOUR TOKEN]

To use the container image as a base image for a CI job on GitLab CI/CD:

SonarScanner Analysis:
  image: addianto/sonar-scanner-cli:latest
  # Ideally you want to run SonarScanner after the test suite has generated
  # test & coverage report. The following is only an example to run
  # SonarScanner concurrently with CI job(s) in `test` stage.
  stage: test
  script:
    # Obtain the host and token from GitLab CI environment variables
    - sonar-scanner
      -Dsonar.host.url=$SONARQUBE_HOST
      -Dsonar.login=$SONARQUBE_TOKEN
  only:
    # Perform SonarScanner analysis only on `master` branch
    - master

Maintainers

License

SonarScanner CLI is a product of SonarSource and licensed under the GNU Lesser General Public License, Version 3.0.

The Dockerfiles and associated scripts found in this project are licensed under the GNU Lesser General Public License, Version 3.0.