Skip to content

Travis CI

Setting up Travis CI for your project

Travis CI is Continuous Integration tool. You can also read more about Travis CI here

To start setting up Travis CI with your GitHub project, visit https://travis-ci.org/ and click "Sign in with GitHub" in the top right corner, and authorize your GitHub sign in.

  • On the left sidebar search for "My Repositories" and click "+" sign or just go directly to your profile page where you will see a list of your GitHub public repositories. And proceed with executing 3 steps.

1) Flick the switch on the left to your repository name.

2) Add .travis.yml file to your repository root directory. You can read more about customizing .travis.yml file here Minimal example of .travis.yml file for PHP project would look like this.

Debugging Travis CI job using Travis API

However debugging is possible only for private or public repos that have this debugging feature enabled, github issue corresponnding the problem can be found here.

language: php
php:
  - '5.6'
  - '7.1'
  - hhvm # on Trusty only
  - nightly

You can also read more about Travis CI for PHP projects here

3) Push anything to the repository git push origin. And check if Travis CI build proceeds.

Setting up Travis CI cron jobs

For more information how to set up cron jobs visit this page.

Standard EdmondsCommerce Travis CI template

.travis.bash

#!/usr/bin/env bash
readonly DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )";
cd $DIR;
set -e
set -u
set -o pipefail
standardIFS="$IFS"
IFS=$'\n\t'
echo "
===========================================
$(hostname) $0 $@
===========================================
"
rm -f composer.lock
gitBranch=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then echo $TRAVIS_BRANCH; else echo $TRAVIS_PULL_REQUEST_BRANCH; fi)
export gitBranch
git checkout $gitBranch
composer install
git checkout HEAD composer.lock


mkdir -p $DIR/cache/qa && chmod 777 $DIR/cache/qa

echo "
===========================================
$(hostname) $0 $@ COMPLETED
===========================================
"

.travis.yml

language: php
git:
  depth: false
php:
- 7.0
- 7.1
- 7.2
- hhvm
matrix:
  allow_failures:
  - php: hhvm
before_script: bash -x .travis.bash
script: phpUnitQuickTests=0 ./bin/qa
notifications:
  slack:
    on_success: change
    rooms:
      - secure: somehashsomehashsomehashsomehashsomehashsomehashsomehash

Travis-CI slack integration

  • Visit slack apps management page https://vendorname.slack.com/apps/manage
  • Search for Travis CI
  • Click "Add Configuration"
  • Select channel from the dropdown and click "Add Travis CI integration"
  • Copy the line provided under "Encrypting your credentials" section, which should look like this
travis encrypt "account:token" --add notifications.slack 
  • Install command line travis by following instructions here
  • Change directory to your cloned project of your host machine so that .travis.yml file would exist in the location where you currently are. And execute above command.
  • And execute this command travis encrypt "account:token" --add notifications.slack -r vendorname/module
  • This will update your .travis.yml with encrypted token and it is ready to be pushed.

Changing Travis CI notifications frequency

You can read more about it here.

To be notified only when successful build state is no longer successful, for Slack use snippet below.

notifications:
  slack:
    on_success: change
    rooms:
      - secure: somehashsomehashsomehashsomehashsomehashsomehashsomehash