Reference tags rules behaves differently for jobs and includes

Summary

!reference tags shows inconsistent behaviour when used for jobs versus includes.

Steps to reproduce

  1. Create a hidden job to be used as reference tags, like this:
.push_to_default_branch
  rules:
    - if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
  1. Now use it in a job, like this:
hello-world:
  script:
    - echo "hello world"
  rules:
    - !reference [ .push_to_default_branch, rules ]

This works correctly

  1. Instead use the same rule with an include, like this:
include:
  - local: my-other-workflow-file.yml
    rules:
      - !reference [ .push_to_default_branch, rules ]

This fails with an unhelpful error message:

include:rule config should be a hash

Example Project

What is the current bug behavior?

The !reference tag is accepted in one case but not in other.

What is the expected correct behavior?

The !reference tag should have consistent behaviour. It cannot be accepted in one context and rejected in another.

Relevant logs and/or screenshots

As described above...

Output of checks

Results of GitLab environment info

Expand for output related to GitLab environment info
(For installations with omnibus-gitlab package run and paste the output of:
`sudo gitlab-rake gitlab:env:info`)

(For installations from source run and paste the output of:
`sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)

Results of GitLab application Check

Expand for output related to the GitLab application check

(For installations with omnibus-gitlab package run and paste the output of: sudo gitlab-rake gitlab:check SANITIZE=true)

(For installations from source run and paste the output of: sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true)

(we will only investigate if the tests are passing)

Possible fixes