Support variables in rules:changes
Problem to solve
I have some CI jobs which run the same steps on different files and try to DRY my CI by using extends
. However, GitLab does not currently evaluate variables in rules:changes
, which makes this difficult. I can work around it by replacing extends
with the explicit properties, but it makes my CI file unnecessarily verbose.
When setting an environment variable as a path and using that variable in rules:changes, the variable is ignored.
Example
- Create a env variable named
HELM_DIR
and set it tohelm
in the UI. - Create a project that contains
helm/test.txt
- Add the below
gitlab-ci.yml
script to the project:
test0:
script:
- echo "This is test0 and will complete"
- echo $CI_COMMIT_BRANCH
- echo $CI_PROJECT_DIR
test1:
script:
- echo $CI_COMMIT_BRANCH
- echo $CI_PROJECT_DIR
- echo $HELM_DIR
- echo "This is working"
- ls
rules:
- if: $CI_COMMIT_BRANCH
changes:
- $HELM_DIR/**/*
when: on_success
- Make a change to the
helm/test.txt
file or any file in that folder.
The below works when explicitly setting the file path:
test0:
script:
- echo "This is test0 and will complete"
- echo $CI_COMMIT_BRANCH
- echo $CI_PROJECT_DIR
test1:
script:
- echo $CI_COMMIT_BRANCH
- echo $CI_PROJECT_DIR
- echo "This is working"
- ls
rules:
- if: $CI_COMMIT_BRANCH
changes:
- helm/**/*
when: on_success
Intended users
Further details
Benefit would be cleaner-looking CI that is easier to maintain.
Proposal
Support variable use in the rules:changes
clause
Note that $
is a valid character in a path, so we need to enforce a rule that if $SOMETHING
variable exists then we will replace it, otherwise we should leave $SOMETHING
unchanged.
Permissions and Security
No impact
Documentation
Testing
What does success look like, and how can we measure that?
Support variable use in the rules:changes
clause
What is the type of buyer?
Any tier where rules:changes
is available (i.e. free/core and above)
Links / references
This page may contain information related to upcoming products, features and functionality. It is important to note that the information presented is for informational purposes only, so please do not rely on the information for purchasing or planning purposes. Just like with all projects, the items mentioned on the page are subject to change or delay, and the development, release, and timing of any products, features, or functionality remain at the sole discretion of GitLab Inc.