Lesson 12: Continuous Integration

Homepage Content Slides Video


This lesson is under construction. Learn from it at your own risk. If you have any feedback, please fill out our General Feedback Survey.

Continuous Integration

Rough diagram of CI workflow

Continuous Integration is a name for any kind of automated tool that performs the following tasks:

  1. Detects changes to your project
  2. Runs a suite of tests on the changed code
  3. Alerts the people that care if something good/bad happened

CI tools are also known to do a slew of other things:

  • Builds and releases new versions of a package when they’re needed
  • Builds documentation and other parts of a project with each new release

Automated Testing

Automated Testing integrated into Github

Automated testing is the most common, and easiest to setup, CI tool. It integrates with Github (Or whatever service you’re using to host your code), and can be set up to detect changes to a codebase (new Pull Request, new branch, new commit on master/develop, etc). When it’s triggered, it runs your tests automatically. If it finds a problem, it will notify the correct people, usually via email.

Tool: Travis CI

Travis CI logo

Travis CI is very popular among Github users because it is easy to setup with Github projects and integrates well with Github workflows. It’s also free for Open Source projects, although the service itself is not Open Source.

Runs test suites for:

Tool: Jenkins

Jenkins is a more powerful version of Travis, but as a result is more complicated to use and set up. While you can pay to use a public instance of Jenkins, it is more common to run your own instance of Jenkins.

  • Does pretty much anything you can tell a computer to do, automatically.
  • Builds and uploads binaries (releases).
  • Runs tests.
  • Reports build successes/failures.
  • Also has plugins!

TODO: Setup Travis on a GH Repo

We’ve spent the past two lessons building and testing a web app. Now, let’s upload it to Github and set up CI on it. First, if you haven’t already, create a Github account.

Once you’ve done that, go to “Create New” in the upper right corner of the page and click on “New Repository”. Fill the fields out using these values:

Creating a new Github repository
  • Repository name: You can put anything you want here!
  • Description: You can also put anything you want here!
  • Public: Check this field
  • Initialize this repository: Check this field as well
  • Add .gitignore: Python
  • Add a license: Apache License 2.0

Click “Create repository” and you will be taken to your newly created repository. Next, click “Clone or download” and copy the URL inside the textbox. Inside your command line, run git clone <url_you_copied> to make a clone of your repository.

Copy the contents of the “Frameworks” exercise directory into the cloned repository, then add them to Git with git add -A and commit them with git commit. To push your code to Github, use git push origin master. Refresh the repository in your web browser to check that your code was successfully pushed.

Next, go to the Travis CI website and click on “Sign in with GitHub”. This will automatically sync all of your Github repositories to Travis. Go to your profile and locate your repository, then click on the button to enable Travis.

To finish setting up Travis on our respository, we have to add a .travis.yml file. Travis will look for this file in your repository whenever it runs and use it to set configuration options. There are detailed guides and examples for a variety of languages in the Travis documentation, but for our project we’re going to put this in the .travis.yml file:

language: python

    - "2.7"

    - pip install -r requirements.txt

    - python run_tests.py

Add and commit the file, then push it to Github once more. If everything was set up correctly, you should see Travis trigger automatically and start testing your app.

Further Reading

Jenkins Documentation
The Jenkins project documentation. If you need a broad overview read the Getting Started with... docs.
TravisCI Documentation
If you end up working on a large project on GitHub you’re going to interface with TravisCI sooner or later.
CircleCI Documentation
CircleCI is a tool we didn’t get to touch on. It is very similar to Travis.