Taking this example directly from the documentation.
docker build:
script: docker build -t my-image:$CI_COMMIT_REF_SLUG .
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
changes:
- Dockerfile
Dockerfile
is an absolute (from the root of the repository) reference to /Dockerfile
or is it a reference to **/Dockerfile
(zero or more directories deep)?**/Dockerfile
version?**/Dockerfile
, how do I specify the absolute /Dockerfile
version?The path Dockerfile
is an "absolute path" only matching /Dockerfile
.
Precisely speaking: paths are relative to the root of the project directory. Which you can think of as "absolute" for simplicity's sake.
(But technically in a GitLab CI/CD pipeline your code gets checked out on some computer by a Runner (program who runs your pipelines), which does not copy your project files to the machine's filesystem root. The paths that you define are thus not really absolute by a strict definition.)
I linked the docs of
rules:exists
there, because it's only stated explicitly in some parts of the documentation, as onartifacts:paths
as well. But you'll find that this is usually the behaviour of these paths keys. (Under the hood in your example you're specifying a paths key, too:rules:changes:paths
. You're just using the shorthand notation there as the last bullet point below the example states).
To match files anywhere in the project (zero or more directories deep) you need to use wildcard characters and wrap the path in double quotes: "**/Dockerfile"
(last point before the example in the linked docs).
The wrapping in double quotes is prescribed by the documentation, because else the YAML parser might misinterpret your path as a YAML alias referencing a YAML anchor defined with
&*/Dockerfile
(yes,*
and/
are valid there). I guess you don't have such a YAML anchor defined, but it's good to take this precaution.