Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Skip TRAVIS-CI builds for non-build relevant file changes

TRAVIS builds are triggered by every commit to the repository. When hosting github pages with the source (e.g. in the docs folder), changes to the documentation are (usually) not critical to the build itself, so they could be easily skipped. Unfortunately TRAVIS does not offer a file-/foldername-based skip instruction like e.g. AppVeyor's skip_commits field.

But there seem to be two ways of achieving (almost) the same effect. In the following examples changes to the files


should not trigger a TRAVIS build. The first way is using the before_install instruction in .travis.yml:

  - |
    if ! git diff --name-only $TRAVIS_COMMIT_RANGE | grep -qvE '(^\.(git|appveyor))|(^(LICENSE|docs))'
      echo "Only build non-relevant files were updated, not running the CI."

This will not stop TRAVIS from setting up the environment(!) but will exit the build before the install job is started.

To skip the job, one can also add [skip ci] to the commit message. To automate this I've created the following hook .git/hooks/prepare-commit-msg


if git diff --cached --exit-code --name-only -- . ':(top,exclude)docs/' ':!\.git*' ':!\.appveyor.yml' #>/dev/null 2>&1
  /usr/bin/perl -i.bak -pe 'print "[skip travis] " if !$first_line++' "$COMMIT_MSG_FILE"

IMO the disadvanage here is, that this pollutes the git log.

The best solution would be, if TRAVIS could add support for something like the already mentioned skip_commits instruction set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment