Can't use some CI vars in rules
Summary
Some CI environment variables can't be used in rules definition.
Steps to reproduce
- Define a gitlab-CI workflow:
# Execute pipeline only when triggered from the web UI
workflow:
rules:
- if: '$CI_PIPELINE_SOURCE == "web"'
stages:
- stage1
- stage2
- stage3
# Regex is matching $CI_JOB_STAGE anywhere in a comma-separated list string.
job1:
stage: stage1
rules:
- if: '$SKIP_STAGES =~ /(^|.*,)$CI_JOB_STAGE(,.*|$)/'
when: never
- when: on_success
script:
- echo "Running $CI_JOB_NAME in $CI_JOB_STAGE"
# Regex is matching 'stage1' anywhere in a comma-separated list string.
job1a:
stage: stage1
rules:
- if: '$SKIP_STAGES =~ /(^|.*,)stage1(,.*|$)/'
when: never
- when: on_success
script:
- echo "Running $CI_JOB_NAME in $CI_JOB_STAGE"
job2:
stage: stage2
rules:
- if: '$SKIP_STAGES =~ /(^|.*,)$CI_JOB_STAGE(,.*|$)/'
when: never
- when: on_success
script:
- echo "Running $CI_JOB_NAME in $CI_JOB_STAGE"
job2a:
stage: stage2
rules:
- if: '$SKIP_STAGES =~ /(^|.*,)stage2(,.*|$)/'
when: never
- when: on_success
script:
- echo "Running $CI_JOB_NAME in $CI_JOB_STAGE"
job3:
stage: stage3
rules:
- if: '$SKIP_STAGES =~ /(^|.*,)$CI_JOB_STAGE(,.*|$)/'
when: never
- when: on_success
script:
- echo "Running $CI_JOB_NAME in $CI_JOB_STAGE"
job3a:
stage: stage3
rules:
- if: '$SKIP_STAGES =~ /(^|.*,)stage3(,.*|$)/'
when: never
- when: on_success
script:
- echo "Running $CI_JOB_NAME in $CI_JOB_STAGE"
- Run pipeline with
SKIP_STAGES="stage1,stage2"
- See that only jobs with fixed stage name gets skipped (
job1a
andjob2a
), not those using$CI_JOB_STAGE
(job1
andjob2
).
Example Project
https://gitlab.com/dr4Ke/gitlab-issue-ci-vars-in-rules
What is the current bug behavior?
Using these kind of rules:
rules:
- if: '$SKIP_STAGES =~ /(^|.*,)$CI_JOB_STAGE(,.*|$)/'
when: never
- when: on_success
When running a pipeline with SKIP_STAGES="stage1,stage2"
, the job in stage1
and stage2
should be ignored, but they are not.
What is the expected correct behavior?
Ignore jobs from the stages defined in the SKIP_STAGES
variable. The pipeline should only contain jobs from stage3
.
Relevant logs and/or screenshots
Execution without SKIP_STAGES
defined:
Execution with SKIP_STAGES="stage1,stage2"
:
I didn't find any logs related to how the rules are processed. If I can find them somewhere, please kindly point me to the right component and log file. I guess it's the gitlab-task-runner that process them, but I didn't see logs related to rules.
Output of checks
This bug happens on GitLab.com, and on gitlab v13.1.0.
Possible fixes
It seems that the CI_JOB_STAGE
don't get interpreted in the rules evaluation process.