Cannot overwrite `only` with empty array

Replace this template with your information

Describe your question in as much detail as possible:
I’ve read somewhere that it is possible to overwrite when a job that you get from a template by overwriting the conditions with an empty array.

For example:

# In the template /templates/.test.gitlab-ci.yml
  stage: .pre
  script: "echo Test"
    - schedules

# in .gitlab-ci.yml
    - project: 'group/template-collection'
      ref: main
      file: '/templates/.test.gitlab-ci.yml'

# This job should always run
  extends: .job1-test
  only: []

In fact this does not work as expected. Setting only to something else that is always true works as a general workaround but is not really what I’d expect.

Does anybody have experience with overwriting or clearing a part of an extended configurations?

  • What version are you on? Are you using self-managed or
    • GitLab: 15.4.1
    • Runner : 15.4 (but also in CI Lint)

My general use case is a setup, where we have templates stored in a global repository that can be reused in multiple projects (such as security checks) which might be set to run anywhere from .pre, test or .post and might be schedules by default but might need to run on every run on some projects.

I guess this might be a bug, but not really sure.

Thanks for your support!

only/except are no longer developed. I suggest to migrate to rules.

1 Like

But to answer my question: how would I overwrite a rule that tells the job to only run on schedule? Can I define rules: [] ?

It is possible to exclude a key from extend setting it’s value as null. See docs

This works with only as well.

EDIT: just to add an example

  stage: .pre
  script: "echo Test"
    - schedules

  extends: .job1-test
  only: null

  stage: .pre
  script: "echo Test"
    - if: $CI_PIPELINE_SOURCE == "schedule"

  extends: .job2-test
  rules: null
1 Like