Gitlab CI - How to trigger a build only if changes happen on particular set of files

Ishan picture Ishan · Nov 21, 2016 · Viewed 11.9k times · Source

In Gitlab CI, how do you trigger a build only if changes happen on particular set of files?

Is there a way to either include or exclude certain files from triggering a build? For eg: updating README.md, .gitignore files should not cause a build to trigger.

Answer

mhellmeier picture mhellmeier · Oct 21, 2017

UPDATE 2

Only/except seem to be an unstable feature. The doc recommends using rules:changes instead:

job:
  script:
    - build # replace with your build command
  rules:
    - changes:
      - /*.{java, py} # ... or whatever your file extension is

UPDATE 1:

Like Gajus mentioned in the comments, it is now possible!

Merge Request: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/21981

Documentation: https://docs.gitlab.com/ee/ci/yaml/#onlyexcept-basic (Thanks to Connor Shea for the tip in the comments)

Original post:

No, it is not possible – not now!

I think this is the issue you are looking for: https://gitlab.com/gitlab-org/gitlab-ce/issues/19232 – It is a very high rated issue (over 100 thumps-up).

The milestone has changed to Next 3-6 months, 4 months ago. (https://gitlab.com/gitlab-org/gitlab-ce/issues/19232#note_31943850) I hope we will see this function soon.