meta data for this page
  •  

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
git:gitlab:ci:yaml:rules [2024/01/18 12:40] – created niziakgit:gitlab:ci:yaml:rules [2025/01/03 14:06] (current) niziak
Line 12: Line 12:
  
 [[https://docs.gitlab.com/ee/ci/yaml/#ruleschanges|rules:changes]] [[https://docs.gitlab.com/ee/ci/yaml/#ruleschanges|rules:changes]]
 +
 +===== conditional variables =====
 +
 +<code yaml>
 +build:
 +  rules:
 +    - if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
 +      variables:
 +        CCACHE_DISABLE: 1
 +    - if: $CI_COMMIT_TAG
 +      variables:
 +        CCACHE_DISABLE: 1
 +</code>
 +
 +  * [[https://docs.gitlab.com/ee/ci/caching/index.html#use-a-variable-to-control-a-jobs-cache-policy|Use a variable to control a job’s cache policy]]
 +  * [[https://gitlab.com/gitlab-org/gitlab/-/issues/270415#note_1050526105|Support `cache` policies for job `rules`]]
 +
 +
 +<code yaml>
 +workflow:
 +  rules:
 +    - if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
 +      variables:
 +        CCACHE_DISABLE: 1
 +        CACHE_CCACHE_POLICY: pull
 +    - if: $CI_COMMIT_TAG
 +      variables:
 +        CCACHE_DISABLE: 1
 +        CACHE_CCACHE_POLICY: pull
 +    - when: always
 +
 +.ccache: &cache-ccache
 +  key: cache-ccache
 +  paths:
 +    - .ccache
 +  policy: ${CACHE_CCACHE_POLICY}
 +
 +
 +.build-target:
 +  cache:
 +    - <<: *cache-ccache
 +
 +</code>
 +
 +===== negate glob? =====
  
 How to negate ''rules:changes'' pattern? How to negate ''rules:changes'' pattern?
Line 17: Line 62:
 Not possible. ''rules:changes'' takes glob patterns and they are inclusive only. Not possible. ''rules:changes'' takes glob patterns and they are inclusive only.
 You have to specify all paths/patterns to match one by one. You have to specify all paths/patterns to match one by one.
 +
 +BUT:
  
 Glob patterns are interpreted with Ruby’s [[https://docs.ruby-lang.org/en/master/File.html#method-c-fnmatch|File.fnmatch]] with the [[https://docs.ruby-lang.org/en/master/File/Constants.html#module-File::Constants-label-Filename+Globbing+Constants+-28File-3A-3AFNM_-2A-29|flags]] ''File::FNM_PATHNAME | File::FNM_DOTMATCH | File::FNM_EXTGLOB'' Glob patterns are interpreted with Ruby’s [[https://docs.ruby-lang.org/en/master/File.html#method-c-fnmatch|File.fnmatch]] with the [[https://docs.ruby-lang.org/en/master/File/Constants.html#module-File::Constants-label-Filename+Globbing+Constants+-28File-3A-3AFNM_-2A-29|flags]] ''File::FNM_PATHNAME | File::FNM_DOTMATCH | File::FNM_EXTGLOB''
  
-Ruby's fnmatch is used to handle patterns. It doesn't support ''!'' char[[acter+Ruby's fnmatch is used to handle patterns. It doesn't support ''!'' character. 
 + 
 +To write rule to do not match changes in <code>src/**/*</code> directory but matches ''s'', ''sr'', ''src2'': 
 +<code yaml> 
 +rules: 
 +  - changes: 
 +    - "{[^s]*,s,s[^r]*,sr,sr[^c]*,src?*}/**/*" 
 +    - "*" 
 +</code> 
 + 
 +Note: second pattern ''*'' is for match any file (but not directory!) 
 +More, to exclude ''src/'' and ''doc/'':
  
-[[https://stackoverflow.com/questions/69905938/is-there-a-way-to-write-a-glob-pattern-that-matches-all-files-except-those-in-a|Is there a way to write a glob pattern that matches all files except those in a folder?]]+<code yaml> 
 +  rules: 
 +    - changes: 
 +        - "{[^s^d]*,s,d,s[^r]*,d[^o],sr,do,sr[^c]*,do[^c]*,src?*,doc?*}/**/*" 
 +        - "*" 
 +</code>
  
 +More about:
 +  * [[https://stackoverflow.com/questions/69905938/is-there-a-way-to-write-a-glob-pattern-that-matches-all-files-except-those-in-a|Is there a way to write a glob pattern that matches all files except those in a folder?]]
 +  * [[https://stackoverflow.com/questions/73228188/gitlab-ci-cd-ruleschanges-negate-glob/73229777#73229777|gitlab CI/CD rules:changes negate glob]]