Variable substitution in .gitlab-ci.yml has a very limited depth

Summary

Seems that a variable substitution depth in .gitlab-ci.yml is limited to 2.

variables:
  A: The_A
  B: The_B $A
  C: clean verify $B

I the example above variables A and B are substituted properly, but D isn't

Steps to reproduce

Use this simple .gitlb-ci.yml:

variables:
  A: The_A
  B: The_B $A
  C: The_C $B

default:
  image: alpine:latest

yaml vars:
  script:
    - echo A=$A
    - echo B=$B
    - echo C=$C
 
shell vars:
  script:
    - export A0="The_A0"
    - export B0="The_B0 $A0"
    - export C0="The_C0 $A0"
    - echo A0=$A0
    - echo B0=$B0
    - echo C0=$C0

Example Project

See previous section

What is the current bug behavior?

Here is a log from the yaml vars job:

 Running with gitlab-runner 12.8.0 (1b659122)
  on aws-autoscaler-main-0116-3-epgitlabp-us-east-1 xxtg2k-x
Using Docker executor with image alpine:latest ...
00:03
WARNING: Container based cache volumes creation is disabled. Will not create volume for "/cache"
Pulling docker image alpine:latest ...
Using docker image sha256:a187dde48cd289ac374ad8539930628314bc581a481cdb41409c9289419ddb72 for alpine:latest ...
Running on runner-xxtg2k-x-project-2606-concurrent-0 via runner-xxtg2k-x-main-0116-3-1585741896-888c248e...
00:02
Fetching changes with git depth set to 1...
00:01
Initialized empty Git repository in /builds/ce/publication-services/nds/poc/glapi-testbed/.git/
Created fresh repository.
From https://main.gitlab.in.here.com/ce/publication-services/nds/poc/glapi-testbed
 * [new ref]         refs/pipelines/498830 -> refs/pipelines/498830
 * [new branch]      variables             -> origin/variables
Checking out 17139987 as variables...
Skipping Git submodules setup
$ echo A=$A
00:01
A=The_A
$ echo B=$B
B=The_B The_A
$ echo C=$C
C=The_C The_B $A
Job succeeded

As may be seen echo C=$C produced C=The_C The_B $A instead of C=The_C The_B The_A

What is the expected correct behavior?

As mentioned in the previous section, echo C=$C shall produce C=The_C The_B The_A. That means a depth of the variable substitutions shall be unlimited (or practically unlimited) as normal shell variables behave, as mau be seen in a og of the shell vars job:

Running with gitlab-runner 12.8.0 (1b659122)
  on aws-autoscaler-main-1a-epgitlabp-us-east-1 kU2mjXxm
Using Docker executor with image alpine:latest ...
00:02
WARNING: Container based cache volumes creation is disabled. Will not create volume for "/cache"
Pulling docker image alpine:latest ...
Using docker image sha256:a187dde48cd289ac374ad8539930628314bc581a481cdb41409c9289419ddb72 for alpine:latest ...
Running on runner-kU2mjXxm-project-2606-concurrent-0 via runner-ku2mjxxm-main-1a-1585741189-15dd3f58...
00:01
Fetching changes with git depth set to 1...
00:02
Initialized empty Git repository in /builds/ce/publication-services/nds/poc/glapi-testbed/.git/
Created fresh repository.
From https://main.gitlab.in.here.com/ce/publication-services/nds/poc/glapi-testbed
 * [new ref]         refs/pipelines/498830 -> refs/pipelines/498830
 * [new branch]      variables             -> origin/variables
Checking out 17139987 as variables...
Skipping Git submodules setup
$ export A0="The_A0"
00:02
$ export B0="The_B0 $A0"
$ export C0="The_C0 $A0"
$ echo A0=$A0
A0=The_A0
$ echo B0=$B0
B0=The_B0 The_A0
$ echo C0=$C0
C0=The_C0 The_A0
Job succeeded

Relevant logs and/or screenshots

See previous sections.

Output of checks

N/A

Results of GitLab environment info

N/A

Results of GitLab application Check

N/A

Possible fixes

(If you can, link to the line of code that might be responsible for the problem)

Edited by Oleksandr Alesinskyy