Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 378
Ishan Avatar asked Nov 21 '16 03:11

Ishan


People also ask

How do you trigger a build only if changes happen on a particular set of files?

If you are using a declarative syntax of Jenkinsfile to describe your building pipeline, you can use changeset condition to limit stage execution only to the case when specific files are changed. This is now a standard feature of Jenkins and does not require any additional configruation/software.

What triggers GitLab CI?

GitLab CI/CD Trigger is the most common and convenient technique for triggering CI/CD. GitLab CI/CD pipelines, by default, are executed automatically when new commits are pushed to a repository and do not require any intervention once created.

What is used to restrict when a job is executed on your pipeline GitLab?

Run jobs for scheduled pipelines To configure a job to be executed only when the pipeline has been scheduled, use the rules keyword.


3 Answers

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       - dockerfiles/**/* # all files under folder 'dockerfiles' 

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.

like image 68
mhellmeier Avatar answered Sep 21 '22 15:09

mhellmeier


Update: This is now possible as of 11.4, see https://docs.gitlab.com/ee/ci/yaml/#onlychangesexceptchanges

Original post:

There's not currently any way to trigger a build in GitLab CI conditionally based on which files have been edited.

I've thought about this feature myself before, and I think it could be very useful for a number of different use cases.

The closest issue I could find for this is https://gitlab.com/gitlab-org/gitlab-ce/issues/23010

Anyway, to answer your question:

You can't really do this right now – even manually – since there's no way to determine if a merge request has changed a file or not since CI has no concept of a merge request.

Pipelines "understanding" what Merge Requests are should be added sometime soon.

like image 24
Connor Shea Avatar answered Sep 21 '22 15:09

Connor Shea


Accidentally found your question. I thinks it's a little bit late :), but that feature available since version 11.4

see docs

like image 25
NobbyNobbs Avatar answered Sep 18 '22 15:09

NobbyNobbs