CI/CD Variable Types
## Summary This epic aims to introduce a new keyword `type` for members of [the `variables` definition](https://docs.gitlab.com/ee/ci/yaml/index.html#variables). ```yaml variables: GENERAL_PATH: value: "$FILE_PATH" type: text # default ``` We have already two types of variables; `Variable` and `File`; https://docs.gitlab.com/ee/ci/variables/#cicd-variable-types. ## Problem 1 "[CI/CD variable of type "file" do not resolve to file names when referenced within global variable declarations](https://gitlab.com/gitlab-org/gitlab/-/issues/30775)" Some users want to define a file variable using an existing file variable. However, when they do this, the initial file variable is extracted to the new variable instead. The "expected" behavior is that seeing the new variable as a file variable with the path of the existing variable. > `V1` is a file variable with `SOME_VALUE`. ```yaml variables: V2: "$V1" build: script: - 'echo $V1' - 'echo $V2' ``` Output: ``` $ echo $V1 /builds/mkarg/gitlabbugresolvefilevariable.tmp/V1 $ echo $V2 SOME_VALUE ``` The "expected" behabior: ``` $ echo $V1 /builds/mkarg/gitlabbugresolvefilevariable.tmp/V1 $ echo $V2 /builds/mkarg/gitlabbugresolvefilevariable.tmp/V1 ``` ## Problem 2 "[Regexp CI/CD variables are evaluated as strings](https://gitlab.com/gitlab-org/gitlab/-/issues/35438)" When you have a Regexp variable, you cannot use it as a Regexp in `rules`/`only` conditions. For example; ```yaml variables: teststring: 'abcde' pattern: '/^ab.*/' test1: script: exit 0 rules: - if: '$teststring =~ $pattern' test2: script: exit 0 rules: - if: '$teststring =~ /^ab.*/' ``` * The `test1` job is not created because the ~backend makes string comparison between `"abcde"` and `"/'^ab.*/"`. * The `test2` job is created because the ~backend makes regexp comparison between `"abcde"` and `/'^ab.*/`. The expected behavior is that seeing `$pattern` as a regexp pattern in conditions. ## Proposal ### Step 1 Rename `Variable` variable to `Text` variable (https://docs.gitlab.com/ee/ci/variables/#cicd-variable-types). So that we will end up having "Text" and "File" variable types (for now). ### Step 2 Introducing `type: ` for the `variables` syntax; ```yaml variables: var1: value: "hello" type: text # by default var2: value: "$FILE_VAR" type: file ``` This will be undocumented for now because it'll behave the same as before (for now). ### Step 3 Make `type: file` public and change the behavior. ### Step 4 Introducing `type: regexp`. ```yaml variables: pattern: value: "/^ab.*/" type: regexp ```
epic