Unexpected behavior from dotenv variables with rules: if
Affected Version: GitLab Enterprise Edition v16.7.7-ee
Unexpected behavior from dotenv variables with rules: if.
When creating a dotenv: artifact with a specific var (in this case $ENRY), the expressions conditions using !~ or =~ seems to don't apply.
When creating rules: conditions to check wether or not a variable contains a simple string, it does not work.
Example so you can reproduce:
stages:
- build
enry:
stage: .pre
script:
- echo "ENRY=JavaScript,HTML,Java,Makefile,Shell" > enry.env
artifacts:
reports:
dotenv: enry.env
terraform:
needs: [enry]
dependencies: [enry]
stage: build
script:
- echo 'this is building terraform only when there is HCL'
- exit 1
rules:
- when: on_success
- if: $ENRY !~ /HCL/
allow_failure: true
Expected behavior: as $ENRY does not contain HCL, $ENRY !~ /HCL/ evaluates to true and, in this case, it is supposed to allow the job to (soft)fail.
The actual behavior: it does not evaluate to true, skipping that if that make the job to (hard)fail.
Looks like I can use the variables in my script: but not in rules: if with expressions
Also tried the opposite, changing to =~ and including HCL to variable $ENRY but it also does not work