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
.job1-test
  stage: .pre
  script: "echo Test"
  only:
    - schedules

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

# This job should always run
job1
  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.com?
    • 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

.job1-test:
  stage: .pre
  script: "echo Test"
  only:
    - schedules

job1:
  extends: .job1-test
  only: null

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

job2:
  extends: .job2-test
  rules: null
1 Like