Empty variables are not consistantly evaluated in "if conditions"
Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.
Summary
Defining an empty variable in the pipeline and using it in if conditions to trigger certain jobs have in consistent behavior.
- If the variable is the only statement, it evaluates to false
- If the variable is ANDed with a
TRUEstatement, it evaluates to true
Steps to reproduce
Run this .gitlab-ci.yml:
image: busybox:latest
stages:
- build
variables:
TEST_VAR: ""
CI_DEBUG_TRACE: "true"
build1:
stage: build
script:
- echo "The TEST_VAR evaluated to true in this case"
rules:
- if: '$TEST_VAR && $CI_COMMIT_BRANCH == "master"'
build2:
stage: build
script:
- echo "The TEST_VAR is evaluated to false in this case"
rules:
- if: '$TEST_VAR'
Only build1 gets executed.
Example Project
Same as the provided .gitlab-ci.yml file.
What is the current bug behavior?
When an empty variable is used in an if condition:
- If the variable is the only statement, it evaluates to false
- If the variable is ANDed with a
TRUEstatement, it evaluates to true
What is the expected correct behavior?
If the variable is ANDed with a TRUE statement, it should evaluate to FALSE
Relevant logs and/or screenshots
Output of checks
This bug happens on GitLab.com
Results of GitLab environment info
Expand for output related to GitLab environment info
(For installations with omnibus-gitlab package run and paste the output of: `sudo gitlab-rake gitlab:env:info`) (For installations from source run and paste the output of: `sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)
Results of GitLab application Check
Expand for output related to the GitLab application check
(For installations with omnibus-gitlab package run and paste the output of:
sudo gitlab-rake gitlab:check SANITIZE=true)(For installations from source run and paste the output of:
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true)(we will only investigate if the tests are passing)
Possible fixes
As a workaround, one can check on variable like: '$TEST_VAR != ""