CI variables in rules regexp
<!--IssueSummary start--> <details> <summary> Everyone can contribute. [Help move this issue forward](https://handbook.gitlab.com/handbook/marketing/developer-relations/contributor-success/community-contributors-workflows/#contributor-links) while earning points, leveling up and collecting rewards. </summary> - [Close this issue](https://contributors.gitlab.com/manage-issue?action=close&projectId=278964&issueIid=209904) </details> <!--IssueSummary end--> ### Summary I'd like to make my gitlab-ci as generic as possible by defining rules using variables to trigger the pipelines. To that end, I would also like to use variable values in the regexp of my rules. #### Example configuration Here's the sample of my gitlab-ci code: ```yaml variables: JAVA_PROJECTS: ressources|calculateur .onJavaTag: rules: - if: '$CI_COMMIT_TAG =~ /($JAVA_PROJECTS)@(.+)/' ``` #### Example Project I've setup a small test repo with that gitlab-ci here: https://gitlab.com/ArtyMaury/gitlab-ci-bug ### Desired behavior The pipeline should be triggered on a `ressources@1.0.0` tag --- ### Workaround via inputs This [example from the comments](https://gitlab.com/gitlab-org/gitlab/-/issues/209904#note_1588416898) shows how to use variables with regexp via `expand_vars`. ```yaml # .gitlab-ci.yml include: - local: my_template.yml inputs: my_var: $MY_VAR # Defined as a Project variable with value: "my_test|my_value" ``` ```yaml # my_template.yml spec: inputs: my_var: --- test-job: script: echo rules: - if: '"my_value" =~ /^($[[ inputs.my_var | expand_vars ]])$/' ``` Full configuration: ![Screenshot_2023-10-03_at_9.43.50_AM](https://gitlab.com/gitlab-org/gitlab/uploads/19cc46937323bb74b87a6ba5854e21b5/Screenshot_2023-10-03_at_9.43.50_AM.png) This results in `test-job` added to the pipeline. **NOTE:** `expand_vars` currently **only** supports the same variables available to `include`. Documentation: https://docs.gitlab.com/ee/ci/yaml/inputs.html#expand_vars – so variables defined with the global or job-level `variables:` keyword cannot be expanded. Neither can job-level predefined variables.
issue