Workflow variables do not take precedence over global variables
Summary
Pipelines that consist only of jobs using rules:if with user-defined CI variables are not triggered if the variables are set in workflow:rules:variables. This results in a pipeline that cannot be triggered to run.
I have a pipeline where all jobs depend on a variable, MY_WORKFLOW, and when the pipeline is run without setting MY_WORKFLOW explicitly or with a default value the pipeline cannot be triggered.
I believe this is bug because of the documentation quoted here:
When the condition matches, the variable is created and can be used by all jobs in the pipeline. If the variable is already defined at the global level, the workflow variable takes precedence and overrides the global variable. source: https://docs.gitlab.com/ee/ci/yaml/#workflowrulesvariables
If that were true then the global variable MY_WORKFLOW, which is able to be used in jobs with rules:if, should be overridden by workflow:rules:variables but it is not.
Steps to reproduce
-
Create a
.gitlab-ci.ymlfile. -
In the CI file, add a job with a
workflow:rules:variablesand defined a variable, e.g.MY_WORKFLOW.workflow: rules: - if: $MY_WORKFLOW =~ /all/ when: always variables: MY_WORKFLOW: bootstrap,test,build,deploy - if: $MY_WORKFLOW && $MY_WORKFLOW != "all" when: always -
Add jobs to the CI file that use a
rules:ifthat check the variable defined inworkflow:rules:variables.test: rules: - if: $MY_WORKFLOW =~ /test/ when: always stage: test script: [exit 0] -
Attempt to trigger this pipeline with the variable set to
all, e.g.MY_WORKFLOW=all
Example Project
https://gitlab.com/mutter1/pipeline-bug-reproducer-0
What is the current bug behavior?
The pipeline cannot be triggered.
What is the expected correct behavior?
The pipeline is triggered.
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)
