Fakultas Ilmu Komputer UI

Skip to content
Snippets Groups Projects

Sonar Scanner CLI Image for Flutter

Sonar Scanner CLI with Flutter dependencies 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 ichlaffterlalu/sonar-scanner-flutter-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 ichlaffterlalu/sonar-scanner-flutter-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 (sample includes multi-branch analysis support):

SonarScanner Analysis Dev:
  image: ichlaffterlalu/sonar-scanner-flutter-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
    # Short-lived branches has a target (parent) branch, which in this case
    # is `staging`.
    - sonar-scanner
      -Dsonar.host.url=$SONARQUBE_HOST
      -Dsonar.login=$SONARQUBE_TOKEN
      -Dsonar.projectKey=$SONARQUBE_PROJECT_KEY
      -Dsonar.branch.name=$CI_COMMIT_REF_NAME
      -Dsonar.branch.target=staging
  except:
    # Perform SonarScanner analysis for short-lived branches
    # (exclude `master` and `staging`)
    - master
    - staging

SonarScanner Analysis:
  image: ichlaffterlalu/sonar-scanner-flutter-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
      -Dsonar.projectKey=$SONARQUBE_PROJECT_KEY
      -Dsonar.branch.name=$CI_COMMIT_REF_NAME
  only:
    # Perform SonarScanner analysis for long-lived branches only on
    # `master` and `staging` branch
    - master
    - staging

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.