Use CI_* variables in pathname of include in gitlab-ci.yml

As from the documentation Use CI/CD configuration from other files | GitLab i have used this in my .gitlab-ci.yml file to dynamically load config files for a specific branch:

include:
  - versions_${CI_COMMIT_BRANCH}.yml
  - parameters_${CI_COMMIT_BRANCH}.yml

It should include a file having the branch name as part of it (fetched from CI_COMMIT_BRANCH variable).

But when i commit to the branch it refused the pipeline (failed) with this error message:

This GitLab CI configuration is invalid: Local file versions_.yml does not exist!

What do i do wrong?

CI_COMMIT_BRANCH is not on the list of supported variables in include

I don’t get that. The variable is used inside the .gitlab-cu.yml file and i thought i could ANY CI_ variable here. So i guess that pipeline-checking is just getting an error as it does not provide a check-value for CI_COMMIT_BRANCH and so it is empty?

I found a solution by making it conditional with exists:

include:
  - local: versions_${CI_COMMIT_BRANCH}.yml
    rules:
      - exists:
        - versions_${CI_COMMIT_BRANCH}.yml
  - local: parameters_${CI_COMMIT_BRANCH}.yml
    rules:
      - exists:
        - parameters_${CI_COMMIT_BRANCH}.yml

There is a list of variables supported in include in the doc you have linked Use CI/CD configuration from other files | GitLab
CI_COMMIT_BRANCH is not listed.