Parent pipeline vars aren't being inherited in child with parallel+matrix

Dear community,

I’m facing an issue with parent global vars inheritance.

I have in parent pipeline:

###################################
## Vars
#

# I'm trying to overwrite this variable from child pipeline here
variables:
  DISTRO: &deb_distros
    - buster
    - stretch

variables:
  BUILD:
    value:       'True'   # either 'True' or 'False'
    description: 'Runs build pipeline'
  RELEASE: '1.0'

....

BUILD:
  trigger:
    include:
      - project: 'common/pipelines'
        ref: 'main'
        file: 'build.gitlab-ci.yml'
    strategy: depend
  rules:
    - if: $BUILD == 'True'

in the child pipeline

###################################
## Vars
#

variables:
  DISTRO: &deb_distros
    - bullseye
    - buster
    - stretch

variables:
  DISTRO: &ubuntu_distros
    - bionic
    - focal

variables:
  DISTRO: &rpm_distros
    - centos8
    - centos7

......
......

.BUILD:
  stage: build
  script:
    - build.sh

BUILD_DEBIAN:
  extends: .BUILD
  parallel:
    matrix:
      - DISTRO: *deb_distros
  artifacts:
    paths:
      - *.deb

BUILD_UBUNTU:
  extends: .BUILD
  parallel:
    matrix:
      - DISTRO: *ubuntu_distros
  artifacts:
    paths:
      - *.deb

BUILD_RPM:
  extends: .BUILD
  parallel:
    matrix:
      - DISTRO: *rpm_distros
  artifacts:
    paths:
      - *.rpm

I assume my parent pipeline DISTRO var will overwrite the child and I would have only 2 distros for build (buster and stretch), but I’m getting distros from the child pipeline and my build fails:

Appreciate any suggestion, thank you!

There is a limitation with YAML anchors:

You can’t use YAML anchors across multiple files when using the include keyword. Anchors are only valid in the file they were defined in. To reuse configuration from different YAML files, use !reference tags or the extends keyword.

Hm, I’m not sure if that is correct behavior - it turned out, when I use extends in the child pipeline, all vars (hashes) will be merged with strange algo “closest scope wins”:

In other words, I can’t just simply pass variables from parent to child, because child pipeline vars will always take higher precedence if I use extends in the child…

Could somebody suggest any workaround on it?

I’ve created an example for this case:

The pipeline:

Moreover, I found the interesting thing - I define variable RELEASE, and the parent’s RELEASE overrides the child…but for DISTRO it won’t happen ;/