Travis CI for Complete Beginners

If you’re not familiar with continuous integration and don’t already have a repository that you want to build, this guide will show you what it is all about.

You need to sign up for a GitHub account if you do not already have one.

To get started with Travis CI:

  1. On GitHub, fork the example PHP repository.
  2. Sign in to Travis CI with your GitHub account, accepting the GitHub access permissions confirmation.
  3. Once you’re signed in, and we’ve synchronized your repositories from GitHub, go to your profile page and enable Travis CI builds for your fork of the
    travis-broken-example

    repository.

    Note: You can only enable Travis CI builds for repositories you have admin access to.

  4. Take a look at
    .travis.yml

    , the file which tells Travis CI what to do:

    
    
    <span class="s">language</span><span class="pi">:</span> <span class="s">php</span>
    <span class="s">php</span><span class="pi">:</span>
    <span class="pi">-</span> <span class="s">5.5</span>
    <span class="pi">-</span> <span class="s">5.4</span>
    <span class="pi">-</span> <span class="s">hhvm</span>
    <span class="s">script</span><span class="pi">:</span> <span class="s">phpunit Test.php</span>

    This file tells Travis CI that this project is written in PHP, and to test

    Test.php

    with phpunit against PHP versions 5.5, 5.4 and HHVM.

  5. Edit the empty
    NewUser.txt

    file by adding your name to the empty file. Add the file to git, commit and push, to trigger a Travis CI build:

    
    
    <span class="gp">$ </span>git add -A
    <span class="gp">$ </span>git commit -m <span class="s1">'Testing Travis CI'</span>
    <span class="gp">$ </span>git push

    Note: Travis only runs a build on the commits you push after adding the repository to Travis.

    Wait for Travis CI to run a build on your fork of the

    travis-broken-example

    repository, check the build status and notice that the build fails. (Travis CI sends you an email when this happens)

  6. Fix the code by making sure that
    2=1+1

    in

    Test.php

    , commit and push to GitHub. This time, the build does not fail.

    
    
    <span class="gp">$ </span>git add -A
    <span class="gp">$ </span>git commit -m <span class="s1">'Testing Travis CI: fixing the build'</span>
    <span class="gp">$ </span>git push

Congratulations, you have added a GitHub repository to Travis and learnt the basics of configuring builds and testing code.

Note there is no need to make a pull request to the original repository, the build is run on your fork.

src: https://docs.travis-ci.com/user/for-beginners

admin