title: “How to Use SonarCloud” lang: en ref: sonarcloud-how-to permalink: /developers/sonarcloud-how-to/ excerpt: “SonarCloud集成指南” last_modified_at: 2019-11-15T16:55:44+08:00 author: Daniel Qian redirect_from:
{% include toc %}
This guide helps you to integrate SonarCloud in your Travis build.
.travis.yml
Travis use shallow clone by default, and SonarCloud needs commit information, so you need to disable shallow clone:
git: depth: false
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;