Pushing to a new branch runs all jobs when using only:changes
Summary
First off, apologies if this is not actually a ~bug but IMO the behavior is not what I expect.
The upshot of this issue is that builds on NEW branches for monorepos (with many jobs split up by only:changes to sub-dirs) are causing all jobs to trigger, making the build process much longer and computationally expensive than they should be.
To summarize the scenario:
- Take the following
.gitlab-ci.ymlfile, along with 2 filesui.txtandpackages.txtwhich I am using to trigger jobs based on changes:
stages:
- build
.packages:
only:
changes:
- packages.txt
except:
refs:
- tags
build_packages:
extends: .packages
stage: build
script:
- echo 'build packages'
.ui:
only:
changes:
- ui.txt
except:
refs:
- tags
build_ui:
extends: .ui
stage: build
script:
- echo 'build ui'
If I commit a change to ui.txt and push directly to the primary branch (e.g. master or develop), then only build_ui runs, which is expected (since the only:changes condition is met).
The (Perceived) Bug
If I commit a change only to ui.txt and push to a NEW branch (e.g. chore/some-change), then BOTH build_ui and build_packages jobs run in the pipeline. Additionally, I have this same behavior if I create a new branch from the primary branch and make NO changes, and push remotely.
What I Expected
I expected the same behavior as when I push to the primary branch. Ideally, I'd like the changes to be computed based on the diff between the new branch and the branch it originated from.
My setup
- I have tried both the
git cloneandgit fetchstrategies, w/the same behavior. - I have tried multiple permutations of various
only:except:refsrules, with no luck just yet.
Sample Project
https://gitlab.com/tzellman/60105-jobs-test/
Pipeline that should have only run 1 of the jobs: https://gitlab.com/tzellman/60105-jobs-test/pipelines/55403567
Finally, thank you for all the hard work. This is not a major bug/issue, but the longer build times for new branches is causing some frustration.
