Backend: Empty `only`/`except` combined with `rules` (and vice-versa) should be a valid CI config

Currently, if I have the following CI config:

job-a:
  only:
    refs:
      - master
  except:
    refs:
      - merge_requests
  script: echo "foo"

job-b:
  extends: job-a
  rules:
    - if: '$CI_MERGE_REQUEST_ID'
  script: echo "bar"

I get a validation error:

jobs:job-b config key may not be used with `rules`: only, except

Note that we get the same problem if job-a is defined in a template.

Proposal

While the error is preventing clashing conditions, it would be great to be able to make the only/except empty so that we don't get the validation error:

job-a:
  only:
    refs:
      - master
  except:
    refs:
      - merge_requests
  script: echo "foo"

job-b:
  extends: job-a
  only: null
  except: null
  rules:
    - if: '$CI_MERGE_REQUEST_ID'
  script: echo "bar"

The above seems intuitive and in line with how you can make other keywords empty (e.g. before_script: [] or dependencies: [] are familiar patterns). --> [2022-12-12] Updated proposal to use null instead of []/{} in order to remain consistent with excluding a keyword (see discussion).

This proposal would solve #31371 (closed) (which I'm going to close in favor of this actionable proposal).

Notes:

  1. That this proposal should work the same if job-a is defined in a template.

  2. The same thing should apply to rules, rules: null, i.e. the following should be valid as well:

    job-a:
      rules:
        - if: '$CI_MERGE_REQUEST_ID'
      script: echo "foo"
    
    job-b:
      extends: job-a
      rules: null
      only:
        refs:
          - master
      except:
        refs:
          - merge_requests
      script: echo "bar"

Implementation

backend MR
Allow CI only/except to be combined with rules when null !106895 (merged)
Edited by Leaminn Ma