If you are looking for an easy way to apply continuous integration to your projects on Github, Travis CI might be for you. Travis is a service offering continuous integration to your repositories on Github. If you are in the area of software development professionally, I am sure you are doing CI of some flavor: Jenkins, Bamboo, TeamCity, or any other CI tool that fits your needs. And if by any chance you are not (and you probably should!) Travis might be worth having a look at. Or if you are looking for an alternative, some way to reduce load on your existing server infrastructure, something for the projects you are working on in your free time or just out of curiosity. Here is a quick look on Travis.
In this post we will be setting up automated builds for a Github project. Every time commits get pushed onto the repository, we want Travis to automatically trigger an automated build for us so that we know the code still compiles in an environment other than the machine the code were developed on. For this I will again take one of my Android projects as an example.
And here is what to do. First we want to visit travis-ci.org, sign in with our Github account, and select the repositories we want to have automatically build from the list. The list will only show public a.k.a. open source repositories (for private repositories paid plans are available on travis-ci.com).
Once the repository is enabled we need to create a config file specifying how the project should be build, name it
.travis.yml and place it into the repository root. There are a lot of config options and many of those seem to be well documented (cf. docs.travis-ci.com). For our simple Android example we actually do not have to configure much. We specify the
language , in our case
android , the
android components to use, in our case
android-22 , and finally the
build command we want issued. In this case we want to use the gradle wrapper and want the debug version of our APK file assembled.
language: android android: components: - build-tools-22.0.0 - android-22 script: - ./gradlew assembleDebug
Now we push the changes to our Github repository and that is all it takes. Travis will get notified and trigger the build process. And we will be notified by E-Mail if the build succeeded. What is worth noting is that Travis is booting up a clean VM environment for each build. For our Android build a Linux environment running Ubuntu with a lot of preinstalled tools.
Description: Ubuntu 12.04 LTS Release: 12.04 Codename: precise Linux Version 2.6.32-042stab090.5 Cookbooks Version 23bb455 https://github.com/travis-ci/travis-cookbooks/tree/23bb455 OS name: "linux", version: "2.6.32-042stab090.5", arch: "amd64", family: "unix" ...
This obviously makes it very versatile, since we have access to lots of commandline tools, can run our own scripts and even download and install additional software if needed. On the downside, builds take a little bit longer. With my test builds (for instance this one: Build #4), the VM set up seemed to take around 4 minutes (which probably include the job to sit around a process queue) after which console output is started to get displayed. The build itself took 2 minutes, including dependency downloads. Of course these will vary depending on the server and network loads and your codebase.
As we’ve seen so far, integrating automated builds to your projects on Github using Travis is rather simple. Of course there is a lot more to explore besides automating your build process. But that might be the topic for another blog post.