Expose list of changed files in variable that can be acted upon (only/except) using regexp matching
Problem to Solve
There are certain scenarios in software development where you want different behavior in a single repo/CI job based on the files that were changed within that repo for the specific job run:
- Monorepos where multiple builds are stored in a single repository
- Statically rendered content where only the changed content needs to be regenerated
There is a deeper implementation of this discussed in https://gitlab.com/gitlab-org/gitlab-ce/issues/19232, but the longer term, deeper fix brings in a number of edge cases to resolve and taking this approach for now will give us better understanding how people want to use this feature as a first-class option of CI.yml.
Proposal
Add new environment variables containing lists of files updated in the job run
CI_COMMIT_CHANGES - add/changed/removed files from this commit SHA
CI_PUSH_CHANGES - add/changed/removed files from this push, push might contain a multiple commits
This would be a flat newline-delimited list of files without information whether it was added/changed/removed:
app/models/ci/build.rb
spec/models/ci/build_spec.rb
Then, you could use variables with regexp matching to figure out if files changed using variables:
matcher specification:
only:
variables:
- $CI_PUSH_CHANGES =~ /^app\//
This will provide a workable MVC solution in the short term while we further investigate longer term options for more advanced behavior.