Skip to content

SonarCloud

Jonathan Austin edited this page Feb 13, 2019 · 8 revisions

Setting up GitHub, Travis-ci and SonarCloud

Integrate GitHub and SonarCloud

Note - SonarCloud currently does not trigger analyses automatically. It's up to you to launch them inside your existing CI scripts. Installing the application on your organization just removes the need to configure a user token on SonarCloud for the pull request decoration. Automatic analysis is coming.

Integrate GitHub Repo and Travis-ci

Integrate GitHub Repo and SonarCloud via Travis-ci

  • Log into SonarCloud with GitHub account
  • Create a new project under Administration -> Projects Management. The key of the project will be used in the repo's travis.yml.
  • Define the sonarcloud addon in the repo's travis.yml (example below)
addons:
  sonarcloud:
    organization: "sonarcloud_organization_key" # the key of the org you created
    token:
      secure: ********* # encrypted value of your access token
script:
  # The following command line builds the project, runs the tests with coverage and then execute the SonarCloud analysis
  - mvn package sonar:sonar -Dsonar.projectKey="sonarcloud_project_key"

Encrypt SonarCloud access token

  • Create SonarCloud access token for the project under Account -> Security.
  • Encrypt access token via Travis CLI (sample commands below). Travis encrypts the token for a specific repo. This is done by running the encryption command in the repo's project directory.
  • Copy encrypted text into travis.yml
gem install travis
## As using travis-ci.com we need to login first
travis login --pro
## Change into your project repo directory
cd project
## Encrypt the access token you generated
travis encrypt --com <access-token>

References

Clone this wiki locally