Travis ci

Xavier Garcia Buils edited this page Jun 8, 2015 · 5 revisions

Once you have your tests running and passing in the cloud, it is time to setup zuul to run in a continuous integration server. For this we will use travis-ci but any of your favorite CI services will work with zuul.

1. getting started

Take a look at the travis-ci getting started guide for node.js. Don't worry! your project doesn't have to be in node.js, we just use that guide to test our javascript.

2. enable the travis webhook

Visit your travis profile page and make sure the repo you want to test is enabled. This is required before moving on to the next steps.

3. create a travis.yml config file

Similar to the .zuul.yml config file we created for zuul, we need to create a simple file for travis. In your project directory, open .travis.yml with your editor

language: node_js
  - '0.10'

Copy and paste the above into that file. Yes, we still write node_js even tho our code is for a browser. This is so travis knows how to test our code.

4. create a package.json file

In order for the above travis configuration to work, we need to create a file with some meta information about our project. This file is called the package.json file and will contain our project name, and how to run zuul. Create and edit the package.json file in your project directory.

    "name": "<put your project name here>",
    "devDependencies": {
        "zuul": "3.0.0"
    "scripts": {
        "test": "zuul -- test.js"

That's it! Lets look at the important lines.

  • devDependencies simply tells npm what to install before running tests. Travis will actually do this for us via the npm install command in our project directory.
  • scripts will be run by travis via the npm test command to actually run our tests. Tests will consider passing if this command returns successfully. You can actually test it locally by running npm test in your terminal.

5. final step

The final step is very important. Remember how we configured the .zuulrc file in our local home directory with our sauce username and key? Well, we need to somehow get those keys to travis. Again we don't want to commit cleartext keys into our repo. Luckily travis has an awesome feature called secure environment variables. This lets us encrypt those environment variables and make them available to our build on travis.

First, install the travis rubygem which will create the encrypted variables. (Alternatively, you can use the travis-encrypt if you haven't rubygem).

gem install travis

Once travis has installed, run the following commands

travis encrypt SAUCE_USERNAME=<sauce username> -r <travis-username>/<repo> --add
travis encrypt SAUCE_ACCESS_KEY=<sauce api key> -r <travis-username>/<repo> --add

Your .travis.yml file will now look something like the following

language: node_js
- '0.10'
  - secure: avoHtpVx6AjEeoTwSESLMryzSzrGLhw4em+lbbheNex3KavITtI+AF6b9FCjMkvaLHz0+ylCQ2773mmXAmUMt9sshpGjwzWziAfz1t6dzb8dxq20r6s+tVQ2Q3p9EhhR+QXvLdCetNzJowbDGpGZV0sYQQzALuXeTaZooDXIsJ4=
  - secure: Hl1SmeCUgpg+QMKJ2gtP1PbtU4s63j6aqpITSECj+Pf0+ByJwWN8GIv3Cm4kOkQH0htYl7RYw6CqyEyVyd4rAogYInftDYbOVgumqKisn1RykgJ0FG7V1FkUpkk+TVFvM84h7DyFFBxTyeLaCSPwXZSm/MaldYk2izWTSQfE/Ek=


Make sure to git add .zuul.yml .travis.yml package.json, commit and push your repo. If everything was done right, travis will be notified of your commit, clone your repo, install zuul, run zuul, and finally tell you if your tests passed or failed!

Further instructions

Check this page for an example set up using the matrix feature.