Travis CI Tutorial

This is a short guide to using Travis CI with your cloud platform-hosted code repository. If you’re new to continuous integration or would like some more information on what Travis CI does, start with Core Concepts for Beginners instead.

Prerequisites #

To start using Travis CI, make sure you have:

To get started with Travis CI using GitHub #

  1. Go to Travis-ci.com and Sign up with GitHub.

  2. Accept the Authorization of Travis CI. You’ll be redirected to GitHub. For any doubts about the Travis CI GitHub Authorized OAuth App access rights message, please read more details below

  3. Click on your profile picture in the top right of your Travis Dashboard, click Settings, and then the green Activate button, and select the repositories you want to use with Travis CI.

Or click the Activate all repositories using GitHub Apps button on the Getting Started page to activate all your repos.

  1. Add a .travis.yml file to your repository to tell Travis CI what to do.

    The following example specifies a Ruby project that should be built with Ruby 2.2 and the latest versions of JRuby.

    language: ruby
    rvm:
     - 2.2
     - jruby
    

    The defaults for Ruby projects are bundle install to install dependencies, and rake to build the project.

  2. Add the .travis.yml file to git, commit, and push to trigger a Travis CI build:

    Travis only runs builds on the commits you push after you’ve added a .travis.yml file.

  3. Check the build status page to see if your build passes or fails according to the return status of the build command by visiting Travis CI and selecting your repository.

Travis CI GitHub OAuth App access rights #

When you sign in to travis-ci.com using GitHub for the first time, you will receive a message from GitHub saying:

Travis CI by travis-pro wants to access your [account name] account.

and in the repositories section it will state:

This application will be able to read and write all public and private repository data.

This is not how Travis CI accesses your data, however we can explain it later in the process.

The warning is triggered due to GitHub OAuth App permissions which Travis CI uses, and due to the available granularity of permission scopes (see GitHub Scopes for OAuth Apps documentation ).

Travis CI does not access all your repositories by default.

Once you acknowledge the access rights, you will see Travis CI OAuth application present in your GitHub Authorized OAuth Apps list, however you need to explicitly configure which repositories Travis CI has access to within your travis-ci.com account. The configuration is done during the activation of Travis CI for your repositories. You can use either the ‘All repositories’ option or the ‘Only select repositories’ option during the activation process.

When the Travis CI activation has completed, you will see the actual Travis CI GitHub Application installed in Installed GitHub Apps section.

Travis CI uses OAuth permissions in the following way:

1) Travis CI’s system synchronizes certain metadata with GitHub. This metadata is required for proper service functioning. In particular, we sync users, orgs, memberships, repos, permissions and, (optionally) branches. This type of sync happens either once a day by schedule or per the user’s request. You can find more information and source code in this repository

2) In order to run builds, Travis CI’s system clones a repository, from which the build is triggered, to the build environment. The build environment is an isolated virtual machine or an LXD container, which gets terminated as soon as the build finishes. Cloning happens only after a build request, and therefore only for the repositories explicitly enabled at GitHub settings.

3) To set up a build environment and prepare the build, Travis CI’s system fetches and processes the .travis.yml config file from the repository and the branch explicitly specified in the build request, triggered by GitHub.

4) Travis CI’s system reports build results back to GitHub via its Checks API.

Read more about it: GitHub permissions used by Travis CI.

To get started with Travis CI using Assembla #

This section documents the new Assembla option that is currently in beta.

  1. Go to Travis-ci.com and Sign up with Assembla.

  2. Accept the Authorization of Travis CI. You’ll be redirected to Assembla.

  3. Click on your profile picture in the top right of your Travis Dashboard, click Settings, and toggle the repositories you want to use with Travis CI.

  4. Create a .travis.yml in your repository to tell Travis CI what to do.

    The following example specifies a Ruby project that should be built with Ruby 2.2 and the latest versions of JRuby.

    language: ruby
    rvm:
     - 2.2
     - jruby
    

    The defaults for Ruby projects are bundle install to install dependencies, and rake to build the project.

  5. Add the .travis.yml file to a specific location in your repository:
    1. Git Repository: in the root of the repository (main and branches).
    2. SVN Repository:
      1. In the /trunk/ (default is /trunk/.travis.yml) for builds to run after commits to trunk.
      2. In the /branches/<branch name>/ (e.g.,/branches/abc/.travis.yml for branch named abc) for builds to run after commits to a specific branch.
    3. P4 (Perforce Helix Core) Repository:
      1. In the /<depotname>/main/ (default is /depot/main/.travis.yml) for builds to run after submits to /<depotname>/main.
      2. In the directory respective to specific stream /depot/<stream name>/.travis.yml (e.g., /depot/abc/.travis.yml for stream abc) for builds to run after submits to a specific stream.
  6. Commit and push/submit to trigger a Travis CI build:

    Travis only runs builds on the commits you push after you’ve added a .travis.yml file.

  7. Check the build status page to see if your build passes or fails according to the return status of the build command by visiting Travis CI and selecting your repository.

IMPORTANT

Perforce depot/repository may be very heavy, so downloading it fully for build (e.g., terabytes of data) is often unwanted, as the source code to be built/tested is only a fraction of the whole depot size. To download it partially, a Travis CI user must define a specific subpath, which is later downloaded by the Travis CI build job. Such subpaths may be defined using the perforce_test_path tag within a .travis.yml file. If the property is not provided, the default behavior is downloading the whole depot/repository. See the example below for reference.

   dist: focal
   language: ruby
   rvm:
    - 2.2
    - jruby
   perforce_test_path: /your/subpath/within/repository/which/will/be/downloaded

Perforce and SVN builds are currently available only for Linux Ubuntu and standard amd64 CPU architecture build environments, starting from Bionic Beaver Ubuntu distribution.

Travis CI access rights to Assembla #

Read more about it: Assembla permissions used by Travis CI.

To get started with Travis CI using Bitbucket #

This section documents the new Bitbucket option that is currently in beta.

  1. Go to Travis-ci.com and Sign up with Bitbucket.

  2. Accept the Authorization of Travis CI. You’ll be redirected to Bitbucket.

  3. Click on your profile picture in the top right of your Travis Dashboard, click Settings, and toggle the repositories you want to use with Travis CI.

  4. Add a .travis.yml file to your repository to tell Travis CI what to do.

    The following example specifies a Ruby project that should be built with Ruby 2.2 and the latest versions of JRuby.

    language: ruby
    rvm:
     - 2.2
     - jruby
    

    The defaults for Ruby projects are bundle install to install dependencies, and rake to build the project.

  5. Add the .travis.yml file to git, commit, and push to trigger a Travis CI build:

    Travis only runs builds on the commits you push after you’ve added a .travis.yml file.

  6. Check the build status page to see if your build passes or fails according to the return status of the build command by visiting Travis CI and selecting your repository.

Travis CI access rights to BitBucket #

Read more about it: BitBucket permissions used by Travis CI.

Get started with Travis CI using GitLab #

This section documents the new GitLab option that is currently in beta.

  1. Go to Travis-ci.com and Sign up with GitLab.

  2. Accept the Authorization of Travis CI. You’ll be redirected to GitLab.

  3. Click on your profile picture in the top right of your Travis Dashboard, click Settings, and toggle the repositories you want to use with Travis CI.

  4. Add a .travis.yml file to your repository to tell Travis CI what to do.

    The following example specifies a Ruby project that should be built with Ruby 2.2 and the latest versions of JRuby.

    language: ruby
    rvm:
     - 2.2
     - jruby
    

    The defaults for Ruby projects are bundle install to install dependencies, and rake to build the project.

  5. Add the .travis.yml file to git, commit, and push to trigger a Travis CI build:

    Travis only runs builds on the commits you push after you’ve added a .travis.yml file.

  6. Check the build status page to see if your build passes or fails according to the return status of the build command by visiting Travis CI and selecting your repository.

Travis CI access rights to GitLab #

Read more about it: GitLab permissions used by Travis CI.

Switching accounts #

You can easily switch between your cloud platform provider accounts:

  1. Click on your account icon in the top right corner on Travis-ci.com.

  2. Select the desired account and have fun using Travis CI.

Selecting a different programming language #

Use one of these common languages:

language: ruby
language: java
language: node_js
language: python
language: php
language: go

If you have tests that need to run on macOS or your project uses Swift or Objective-C, use our macOS environment:

os: osx

You do not necessarily need to use macOS if you develop on a Mac. macOS is required only if you need Swift, Objective-C, or other macOS-specific software.

Travis CI supports many programming languages.

More than running tests #

Travis CI isn’t just for running tests. There are many other things you can do with your code:

Further Reading #

Read more about: