Q: GitLab CI: Using environment variable in exists rule I want my CI job to only run if a file exists. My path contains environment variable that is passed on the GitLab CI/CD schedule variables.
  rules:
     - exists:
        - foo/bla/${ENV}/foo.json

When I use the $ENV environment variable (with or without curly braces), it does not work (the job is not created). However, when I explicitly state the full path (foo/bla/prod/foo.json), it does work.
My concern is that GitLab does not evaluate the environment variables when they read the rules.
Any help would be appreicated.

A: Currently this is not possible but there exists an open issue for this use case.

A: This should be supported with GitLab 15.6 (November 2022):

CI/CD variable support in rules:exists configuration
The more complex your .gitlab-ci.yml configuration is, the more difficult it is to maintain and scale.
By adding support for CI/CD variables with the rules: exists keyword, you can now use variables for paths or filenames.
Having a single source of truth by storing frequently used values in variables ensures consistent behavior and makes your configuration easier to manage.

See Documentation and Issue.

