Integrating Travis, SonarQube and GitHub

This post is able how I had integrated Travis-CI.org, SonarQube.com and GitHub so it will process pull requests and put them as part of the GitHub commit.

TL;DR

  1. Create tokens for your account in SonarQube.com accounts security.
  2. Create a GitHub personal access token with repo access.
  3. Enable Travis CI to build your repository.
  4. Create a .travis.yml file.
    language: java
    jdk:
      - oraclejdk8
    sudo: false
    cache:
      directories:
      - "$HOME/.m2/repository"
      - "$HOME/.sonar/cache"
    addons:
      sonarqube:
        organization: your-organization-id
    install:
    - mvn dependency:go-offline
    script:
    - mvn verify site sonar:sonar -Dmaven.test.failure.ignore=true
    
  5. Install travis command line tool (best to do this on a Mac or Linux if you have not set up Ruby on Windows)
    gem install travis
  6. Add the tokens using travis encrypt
    travis encrypt <token from sonarqube.com> --add addons.sonar.token
    travis encrypt SONAR_GITHUB_TOKEN=<token from github.com> --add
  7. If everything went well you should have the following in your .travis.yml file
    env:
      global:
      - secure: WZw...=
    
  8. Finally commit and push the changes to the .travis.yml file back to github.

A full example and annotated travis.yml is available in