How to Use SonarCloud

This guide helps you to integrate SonarCloud in your Travis build.

Steps

  1. First, you should be member of Apache Orgnization in Github.
  2. Login to sonarcloud.io with your Github credentials.
  3. Create an JIRA ticket in Infrastructure asking to create a project at SonarCloud, here is an example. You should provde Github repo url, project-key (the id of your project in SonarCloud), Github id for the Admin of this project, generally speaking that’s yours.
  4. Wait for the INFRA team creating the project, after that you will see it at SonarCloud.
  5. Follow the SonarCloud instructions modify project’s .travis.yml

About Shallow Clone

Travis use shallow clone by default, and SonarCloud needs commit information, so you need to disable shallow clone:

git:
  depth: false

About PR

Travis doesn’t support SonarCloud in PR build, you should modify your build script like this:

echo "TRAVIS_PULL_REQUEST=$TRAVIS_PULL_REQUEST"
if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
  echo "Not a pull request build, running build with sonar"
  mvn ... sonar:sonar -Dsonar.projectKey=<project-key>
else
  echo "Pull request build or local build"
  mvn ...
fi;

References