When using !reference, top level variables don't merge with included

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

Summary

By default, top-level variables merge across the files when using include. The reference documentation is available at https://docs.gitlab.com/ee/ci/yaml/includes.html#override-included-configuration-values.
If the included file uses !reference to define top-level variables, they disappear if the main file has top-level variables.

Steps to reproduce

  1. .gitlab-ci.yml
    include:
      - local: test.gitlab-ci.yml
    
    variables:
      TEST1: "1"
    
    test:
      image: busybox:latest
      script:
        - env
  2. test.gitlab-ci.yml
    .test:
      TEST1:
        value: "2"
        description: "TEST1"
      TEST2:
        value: "2"
        description: "TEST2"
    
    variables: !reference [.test]

Example Project

https://gitlab.com/vitoyucepi/gitlab-issue-498769

What is the current bug behavior?

The top-level variables are not merged if !reference is used in the included file and the main file has top-level variables.

What is the expected correct behavior?

  1. Top-level variables should merge.
  2. New pipeline interface should display prefilled variables.

Relevant logs and/or screenshots

N/A

Output of checks

This bug happens on GitLab.com

Results of GitLab environment info

N/A

Results of GitLab application Check

N/A

Possible fixes

N/A

Additionally

Is it possible to merge dictionaries when using !reference?

Edited by 🤖 GitLab Bot 🤖