Skip to content
GitLab
Next
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • GitLab GitLab
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 44,761
    • Issues 44,761
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
    • Requirements
  • Merge requests 1,329
    • Merge requests 1,329
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Container Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Metrics
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • GitLab.orgGitLab.org
  • GitLabGitLab
  • Issues
  • #34272
Closed
Open
Issue created Oct 16, 2019 by Mike Atkinson@atkinsonm☁

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

  1. Create a env variable named HELM_DIR and set it to helm in the UI.
  2. Create a project that contains helm/test.txt
  3. 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
  1. 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

Edited Aug 31, 2020 by Jason Yavorska
Assignee
Assign to
Time tracking