032 Travis CI

01 Feb 2013

Travis CI is a hosted continuous integration platform fre for open source. In this episode, we will create 3 hello world projects on Sinatra (Ruby), Flask (Python) and NodeJS (JavaScript) and see how we can use Github and Travis CI for easy continuous integration.

Download video: mp4

Sample code: Github

Similar episodes: 004 GIT, 015 Github, 021 GruntJS

##Background on Travis CI

  1. Travis: Main Website, Documentation, Blog, Twitter
  2. Continuous Integration: Wikipedia, Martin Fowler

##Things to learn with Travis CI

####1. Start a simple Travis CI + Sinatra(Ruby)

  1. create a new file hello.rb

    ``` require ‘sinatra’

    get ‘/’ do “Hello World in Ruby, Sinatra!” end ```

  2. include a new file .travis.yml

    language: ruby rvm: - "1.9.3" gemfile: Gemfile.ci

  3. create a Rakefile with at least one default task

    ``` require ‘rake’

    task :default do puts “Hello World!” end ```

  4. create a Gemfile.ci that the travis will use

    source 'http://rubygems.org'
    gem 'sinatra'
    gem 'rake'
  5. create github repo and git push to github
  6. Sign in to travis
  7. Go to travis profile page and turn on the newly listed repo
  8. Copy the Travis Token from Profile > Profile Tab > Token
  9. In Github go to the Repo Settings > Service Hooks > Travis > Check Active + Insert Token > Test Hook + Update Settings
  10. Create the readme.md file or make any other minor changes to push to github once again

####2. Start a simple Travis CI + Flask(Python)

  1. create a new file hello.py

    ``` from flask import Flask app = Flask(name)

    @app.route(“/”) def hello(): return “Hello in Flask, Python!”

    if name == “main”: app.run()


  2. include a new file .travis.yml

    language: python python: - "2.7" install: "pip install -r requirements.txt --use-mirrors" script: - python setup.py test

  3. create a setup.py

    ``` from setuptools import setup, find_packages

    setup( name=’Hello’, version=’1.0’, long_description=doc, packages=find_packages(), include_package_data=True, zip_safe=False, install_requires=[‘Flask’] ) ```

  4. create a requirements.txt that the travis will use

  5. Same as Step 5 to Step 10 for Sinatra(Ruby)

####3. Start a simple Travis CI + Node(JavaScript)

  1. create a new file hello.js

    ``` var http = require(‘http’);

    http.createServer(function (req, res) { res.writeHead(200, {‘Content-Type’: ‘text/plain’}); res.end(‘Hello World in Node!\n’); }).listen(1337, ‘’);

    console.log(‘Server running at’); ```

  2. include a new file .travis.yml

    ``` language: node_js node_js: - 0.8


  3. create a grunt.js with just one task for linting

    ``` module.exports = function(grunt) {

    grunt.initConfig({ lint: { files: [‘hello.js’] } });

    grunt.registerTask(‘default’, ‘lint’); grunt.registerTask(‘travis’, ‘lint’);

    }; ```

  4. create a package.json that the travis will use

       "name": "hello-node",
       "description": "A demo for nodejs travis and grunt",
       "author": "sayanee <[email protected]>",
       "version": "0.0.1",
       "devDependencies": {
         "grunt": "~0.3.17"
       "scripts": {
         "test": "grunt travis --verbose"
  5. Same as Step 5 to Step 10 for Sinatra(Ruby)

##More Resources on Travis CI

  1. Browser Extension
  2. Notification
  3. Status Image [cache issue just incase it doesn’t update]
  4. Travis CI + PHP + Composer screencast
  5. Travis CI Slides
  6. Command Line Client

##Build Link of this Episode

FripFrap a frontend banter in 30mins or less by Divya and Garann.