58

Is it possible to override the global before_script with an empty before_script within a job?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Alexander Herold
  • 1,057
  • 2
  • 9
  • 20

2 Answers2

82

Yes, the local before_script overrides the global before_script. To keep the .yml sintax valid, use a command that does nothing.

before_script:
- global before script

job:
  before_script:
  - ''
rpadovani
  • 7,101
  • 2
  • 31
  • 50
  • 14
    How does one do the opposite? Not override the parent `before_script`? – David Callanan Jul 31 '19 at 11:26
  • @DavidCallanan you can either not declare `before_script` in your job to avoid overriding it or reference the global `before_script` to extend it in your job. https://docs.gitlab.com/ee/ci/yaml/#reference-tags – Antony Fuentes Sep 15 '21 at 17:59
  • 1
    To create a reference to the global `before_script`, enter this line into your local `before_script` as if it were a regular command: `- !reference [before_script]`. This way you can not override it but extend it with additional commands. – gekkedev Apr 28 '22 at 09:17
  • @jakub-kania solution is much "clearer" in my opinion – Izydorr Jan 16 '23 at 11:21
74

You should use an empty array notation.

before_script:
- global before script

job:
  before_script: []
  script:
  - test
Jakub Kania
  • 15,665
  • 2
  • 37
  • 47