Predefined project variables are not working under include:rules

Summary

I am trying to split my .gitlab-ci.yml into multiple files using includes as described in https://docs.gitlab.com/14.3/ee/ci/yaml/index.html#rules-with-include. My idea was to have individual files for different workflows that I need and then conditionally include them via rules depending on whether the pipeline is running on a merge request or a branch and the name of the respective branch, just like the following example from https://docs.gitlab.com/14.3/ee/ci/yaml/index.html#rules-with-include.

include:
  - local: builds.yml
    rules:
      - if: '$INCLUDE_BUILDS == "true"'

test:
  stage: test
  script: exit 0

That page reads "You can use rules with include to conditionally include other configuration files. You can only use rules:if in include with certain variables", and "certain variables" links to a passage that says "In include sections in your .gitlab-ci.yml file, you can use:

  • $CI_COMMIT_REF_NAME predefined variable in GitLab 14.2 and later.
  • Project variables
  • Group variables
  • Instance variables
  • Project predefined variables".

From the above I conclude that predefined project variables like CI_COMMIT_BRANCH, CI_COMMIT_TAG, CI_PIPELINE_SOURCE, and others listed at https://docs.gitlab.com/ee/ci/variables/predefined_variables.html can be used to conditionally include local files. Nonetheless, I wasn't able to make it work - the jobs simply won't get scheduled as if these variables are not defined. I and using a self-hosted runner version 14.3.2 with gitlab.com, but I've checked it with shared runners and the resulting pipeline is exactly the same.

Steps to reproduce

  1. Check .gitlab-ci.yml file in the example project below. Confirm that it contains five includes each depending on a single predefined variable being defined.
  2. Run the pipeline, observe that only two of five jobs have been scheduled and executed.

Example Project

https://gitlab.com/atweel/research-and-development/projects/gitlab-ci-conditional-includes-demo

What is the current bug behavior?

Conditional includes that use CI_COMMIT_BRANCH, CI_COMMIT_TAG, and CI_PIPELINE_SOURCE variables do not get scheduled when the pipeline is run, which means that these variables are not defined at the time when the includes get evaluated.

What is the expected correct behavior?

All variables listed under https://docs.gitlab.com/ee/ci/variables/predefined_variables.html are defined and can be used to control conditional includes.

Relevant logs and/or screenshots

Here is a screenshot of the following pipeline: https://gitlab.com/atweel/research-and-development/projects/gitlab-ci-conditional-includes-demo/-/pipelines/386964623

Screen_Shot_2021-10-12_at_18.15.43

Output of checks

This bug happens on GitLab.com

Edited by 🤖 GitLab Bot 🤖