Integrate Github Repo with Travis CI For Scala Play2.0 and MongoDB Project

Reading Time: 2 minutes

Travis CI is a hosted, distributed  continuous integration service used to build and test projects hosted at  GitHub for the open source community.

It supports building software in numerous languages, including Ruby, JavaScript, Java, Scala, PHP, Haskell and Erlang.

A Travis worker comes with a good amount of services you might depend on, including MySQL, PostgreSQL, MongoDB, Redis, CouchDB, RabbitMQ, memcached and others.

Hosting your project on travis-ci.org means you can effortlessly test your library or applications against multiple runtimes and data stores without even having all of them installed locally.

Steps to integrate with Travis-CI :

Step #1 : Sign in Travis-CI with GitHub Account

To get started with Travis CI, sign in through your GitHub Account in https://travis-ci.org/.

Then GitHub will ask you for granting read- and write access.

Step #2 : Activate GitHub Service Hook

After Signing in, you need to activate GitHub Service Hook. For this you have to go  to your profile page in Travis CI where you find the list of your all GitHub’s repositories.Flip the on/off switch for each repository that you want to hook up on Travis CI.

To confirm that Travis CI activated for your repo(s)  , go to settings of your repo on GitHub

Settings -> Service Hooks ->Available Service Hooks  here you find that Travis option  in the list is activated.

When you click on Travis you find that GitHub user-name and Travis token into the settings for the Travis service is  already pre-filled.

Selection_008

Step #3: Add .travis.yml file 

In order for Travis to build your project , add .travis.yml to the root of your repository.

.travis.yml example for Scala , Play 2.0 and MongoDB Project

[sourcecode language=”scala” wraplines=”false” collapse=”false”]
language: scala
scala:
– 2.9.2
– 2.9.1
jdk:
– openjdk7
– oraclejdk7

services:
– mongodb
– memcache

env:
– PLAY_VERSION=2.0.2

before_script:
– wget http://download.playframework.org/releases/play-${PLAY_VERSION}.zip
– unzip -q play-${PLAY_VERSION}.zip
script:
–  sbt test

notifications:
email: false[/sourcecode]

Step #4: Make a Git Push Request for trigger your first build on Travis CI

Once GitHub hook is set up, push your commit that adds .travis.yml to your repository. That should add a build into one of the queues on Travis CI and your build will start as soon as one worker for your language is available.

[sourcecode language=”scala” wraplines=”false” collapse=”false”]
git commit -a -m “Add Travis CI”
git push origin master
[/sourcecode]

Step #5 : Add Status image To README.md

To add a status image  copy the Markdown from  https://travis-ci.org/YOUR_REPO_NAME and paste into your README.md File. For Example :

Selection_010

When you click on it you would redirect to your Travis CI Build Detail Page .

By following the above mentioned steps you can integrate your GitHub Repo with Travis-CI.

For More details refer to following link :  Travis CI Started Guide

For Reference To  Scalajobz   .travis.yml File : https://github.com/knoldus/scalajobz/blob/master/.travis.yml

knoldus/scalajobz  Travis CI Build Configuration  : https://travis-ci.org/knoldus/scalajobz

Written by 

Principal Architect at Knoldus Inc

1 thought on “Integrate Github Repo with Travis CI For Scala Play2.0 and MongoDB Project3 min read

Comments are closed.

Discover more from Knoldus Blogs

Subscribe now to keep reading and get access to the full archive.

Continue reading