1

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.

danielnelz
  • 3,794
  • 4
  • 25
  • 35
Gilbert Williams
  • 970
  • 2
  • 10
  • 24

2 Answers2

0

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

danielnelz
  • 3,794
  • 4
  • 25
  • 35
0

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.

https://about.gitlab.com/images/15_6/variable_support_rule_exists.png -- CI/CD variable support in rules:exists configuration

See Documentation and Issue.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250