Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skip travis build if an unimportant file changed

Tags:

travis-ci

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?

like image 414
landau Avatar asked Jan 26 '18 04:01

landau


People also ask

Which of the following file is used to configure the Travis CI?

Configuration. Travis CI is configured by adding a file named . travis. yml , which is a YAML format text file, to the root directory of the repository.

Which of the following type of commands are supported by Travis CLI?

There are three types of commands: Non-API Commands, General API Commands and Repository Commands. All commands take the form of travis COMMAND [ARGUMENTS] [OPTIONS] .


1 Answers

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.

like image 190
soulshake Avatar answered Oct 24 '22 04:10

soulshake