Excuse the brief answer, but I've just had some success with using the unix glob 'not syntax', ie:
- changes:
- '[^d][^o][^c][^s]**/**/*'
- '*' # above matcher does not match files in base folder
This matches changes to all files not in ./docs/ , and seems to correctly trigger the step for any changes outside that folder, but not for chages within that folder.
edit2: This actually matches each character individually. So will also ignore a folder called licensing
, as there's a rejected match on the third character (c
). '[^d][^o]**/**/*'
is currently doing the job for us, but ymmv.
As a result, other matching rules within the "rules" property will still trigger the job. My whole rules statement needed to be set up to not trigger the job on any other rule:
rules:
- if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH # Run for merges
when: never
variables:
BUILD_ENVIRONMENT: "production"
- if: $CI_MERGE_REQUEST_ID # Run for merge requests
when: never
variables:
BUILD_ENVIRONMENT: "staging"
- changes:
- '[^d][^o][^c][^s]**/**/*'
- '*'
This isn't well tested yet though!
edit:fixed a little, with inspiration from Jan Spets:
https://gitlab.com/gitlab-org/gitlab/-/issues/32673
and the gitLab source code for the Changes feature:
https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/build/rules/rule/clause/changes.rb