Extends doesn't expands variables correctly
Summary
When using extends with a variable definition (either for the script or the ones within the project) the variable redefinition is lost. In contrast, a YAML anchor performs the job correctly.
Steps to reproduce
variables:
LOCAL: "global"
ANCHOR: "global-anchor"
.echo:
script:
- echo "CI_REGISTRY_IMAGE=${CI_REGISTRY_IMAGE}"
- echo "LOCAL=${LOCAL}"
- echo "ANCHOR=${ANCHOR}"
.my-var:
variables:
# this should be defined within the project variables
CI_REGISTRY_IMAGE: "${CI_REGISTRY_PATH}/tf"
.local-var:
variables:
LOCAL: "local-var"
.local-anchor: &local-anchor
variables:
ANCHOR: "local-anchor"
build:
stage: build
variables:
VER: "latest"
extends: .my-var
extends: .local-var
<<: *local-anchor
extends: .echo
For several levels of extension and redefinition check https://gitlab.com/-/ide/project/adin/variable-test
Actual behavior
The variable redefinition is lost while using extends but it works as intended when using YAML anchors.
Expected behavior
The variable should be redefined when calling an extends that redefines it.
Relevant logs and/or screenshots
Compare the output of https://gitlab.com/adin/variable-test/-/jobs/130977198 the jobs when printing the variable ANCHOR, LOCAL, and CI_REGISTRY_IMAGE. Anchor uses the YAML anchor mechanism and is redefined. However, the other two are not and they use extends.
Environment description
Using gitlab.com. Check the repo with an example https://gitlab.com/adin/variable-test
Used GitLab Runner version
Running with gitlab-runner 11.5.0 (3afdaba6)
on docker-auto-scale fa6cab46
Using Docker executor with image busybox:latest ...
Pulling docker image busybox:latest ...
Using docker image sha256:59788edf1f3e78cd0ebe6ce1446e9d10788225db3dedcfd1a59f764bad2b2690 for busybox:latest ...
Running on runner-fa6cab46-project-9801401-concurrent-0 via runner-fa6cab46-srm-1544119481-c23baa8d...