Run jobs only/except when there are changes for a given path or file
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
- You only want to execute part of the pipeline if the Dockerfile has changed
We will add a new
changes element to only/except which will allow you to specify globs of files in the repo where, only or except in cases where files in that glob were added, modified, or deleted.
only: changes: - Dockerfile - assets/*
Behavior in "New Branch" case
The situation of a new branch is unique when comparing only/except changes since it's unclear in the product (for now) what to compare against. We decided that perhaps the most reasonable solution is to treat the new branch push as a separate event, and therefore to evaluate
true for all files; what this means is that for the first pipeline of a new branch, everything will be built.
This behavior will be OK for some teams, but others will want behavior that is more aware of the target branch this will eventually be merged to, and to evaluate the changes in the branch against that target. We may eventually build that capability into the product, but for now this feature will be most valuable on relatively stable branches (master for sure, but also other longer-lived branches.)