Ability to locally override workflow rules (imported) from included CI yaml files

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

Issue Description

I am trying to include an external GitLab CI YAML file into my project local .gitlab-ci.yml file. The external YAML, which is in my other GitLab project ci/cd > templates contains some workflow rules:

# ci-cd.yml

workflow:
  rules:
    - if: '$TRACK != null' # TRACK is the environment type (staging/production)
      when: always
    - if: '$CI_PIPELINE_SOURCE =~ /^trigger|pipeline|web|api$/'
      when: always

Below is my project local .gitlab-ci.yml, where I include an external (ci-cd.yml) and a local (.gitlab-ci-test.yml) file:

include:
- '/.gitlab-ci-test.yml'
- project: 'ci-cd/templates'
  file: 'ci-cd.yml'

...

I have defined some jobs in locally included .gitlab-ci-test.yml. The problem is - none of the jobs in .gitlab-ci-test.yml get triggered when I push the changes to GitLab, even when the job has when: always set, as according to GitLab Docs - "workflow rules determine whether or not a pipeline is created". So because none of my workflow rules defined in ci-cd.yml evaluates to true, pipeline isn't being created.

Also, even if I add a job-specific rule like this -

test:
  script:
    - npm run test
  rules:
    - if: $CI_PIPELINE_SOURCE == "push"
      when: always

It wouldn’t help, because as per a discussion in GitLab forums -

You have to specify rules for reach job. Currently the workflow:rules determine if the pipeline is created as a whole, it is not possible to overwrite it with rules. workflow:rules does not function as default rules for all jobs. There is no interaction between those two.

Also, as my last option - if I try to locally add a new workflow rule to .gitlab-ci.yml, in hope that it would act in addition to the global workflow rules, but that actually entirely replaces the workflow rules from included ci-cd.yml file (tested with my project).

NOTE - The external file which has workflow rules is a common CI file used by many projects so this can't be modified to have "push" in $CI_PIPELINE_SOURCE. My intention is to let it be as a global rule and try to 'override' locally in my project.

I hope I was clear in issue description.

Proposal

Ability to locally override workflow rules (imported) from included CI yaml files. For example - given that I am importing a yaml which has 2 workflow rules defined in it, if I add the following workflow rule to my local .gitlab-ci.yml

workflow:
  rules:
    - if: '$CI_PIPELINE_SOURCE == "push"'
      when: always

It should be considered the 3rd rule (in addition to the 2 workflow rules from included yml).

Edited by 🤖 GitLab Bot 🤖