Search code examples
travis-ci

Skip travis build if an unimportant file changed


I use continuous integration with Travis to run my unit tests on every commit. However, sometimes all I want to do is edit the README. Is there a way to skip Travis builds if all the changes are restricted to a whitelisted set of files?


Solution

  • There's no way to directly make Travis dynamically determine, based only on the type of file that has been changed, if it should run a build.

    However, Travis will ignore any commit with [ci skip] or [skip ci] in the commit message.

    Perhaps you could use a git hook (say prepare-commit-msg or similar) to append [ci-skip] to the commit message when only .md files have been modified.

    In the git hook, you could detect this scenario with a command like git diff --exit-code --name-only -- . ':(exclude)*.md'.

    In action:

    $ git diff --name-only
    README.md
    $ git diff --exit-code --name-only -- . ':(exclude)*.md'
    $ echo $?
    0
    

    If any non *.md files have been changed, the command will return 1, otherwise 0.