Unable to use variables in rules regexp
Update
This issue is closed and marked as wontfix as there is an identified workaround available.
The goal per the original description, is to use variable values in the regexp in the if
rule. The example from the comments which has been copied here, does that using regexp via expand_vars
.
# .gitlab-ci.yml
include:
- local: my_template.yml
inputs:
my_var: $MY_VAR # Defined as a Project variable with value: "my_test|my_value"
# my_template.yml
spec:
inputs:
my_var:
---
test-job:
script: echo
rules:
- if: '"my_value" =~ /^($[[ inputs.my_var | expand_vars ]])$/'
Full configuration:
^ This currently works and results in test-job
added to the pipeline. So this is one way that variables can be used in a rule Regex.
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.
Original Description below
Summary
I'd like to make my gitlab-ci as generic as possible by defining rules using variables to trigger the pipelines. But I can't figure out how to uses variables values in the regexp in my if
rule.
Steps to reproduce
Here's the sample of my gitlab-ci code:
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
What is the current bug behavior?
The pipeline doesn't trigger properly
What is the expected correct behavior?
The pipeline should be triggered on a ressources@1.0.0 tag