header

Travis CI Configuration

Travis is a continuous integration service used to build and test software projects hosted at GitHub. Travis is configured by adding a file named .travis.yml which is a YAML format file in the root directory of the repository. Here we have the most basic example:

language: java
jdk: openjdk8

Travis environment contains various versions of Java (Open JDK, Oracle JDK), Gradle and Maven. Travis will search for a pom.xml or build.gradle file in order to use Maven or Gradle. Now for linking your GitHub account with Travis account, please follow this steps:

  1. Go to Travis-ci.com and sign up with GitHub.
  2. Accept the Authorization of Travis. You’ll be redirected to GitHub.
  3. Click the green Activate button, and select the repositories you want to use with Travis CI

In that way when you push a branch to your repository Travis will execute this steps:

  1. Will clone your GitHub repository
  2. gradle assemble
  3. gradle check
  4. gradle test

If previous tasks were successfully executed will generate a build success status:

Build Status

With Travis CI you can also do this tasks:

  1. Run JaCoCo code coverage and fail the build if desired percentage is not met
  2. Run Sonarqube code quality checks
  3. Built Docker image and publish it

Sonarqube Configuration

In order to add Sonarqube you need to add this plugin to your build.gradle file:

plugins {
  id "org.sonarqube" version "2.7"
}

Next step is to set three environment variables in your Travis project configuration:

  • SONAR_LOGIN
  • SONAR_PROJECT

Sonar login is an user token: In your Sonarqube account go to User>My Account>Security Your existing tokens are listed there. Sonar project is your Project Key defined in the Sonar project main section.

Finally in your .travis.yml file you need to add the command required to start Sonarqube scanner process

language: java
jdk: openjdk8
script:
  - ./gradlew test sonarqube

Quality Gate Status

Do not forget to add Sonar server url to your gradle.properties file

systemProp.sonar.host.url=https://sonar.josdem.io/

To browse a project using Travis configuration go here.

Return to the main article

comments powered by Disqus