Skip to content

`default:` keyword for gitlab-ci.yml

Problem to Solve

Top level configuration is messy, with several keywords in place that serve as global defaults for jobs but as a new user of pipelines this isn't necessarily clear. Also, these settings are mixed in with other actual top-level context that serves different purposes (for example, stages:) which makes things even less clear.

Proposal

Move all existing top-level configuration options into default: to clearly indicate their purpose, which is to define default configuration options for all other jobs.

The configuration options to be moved:

  • before_script,
  • after_script,
  • image,
  • services,
  • variables,
  • cache

Keep stages/types to be part of top-level context.

This will be made fully backward compatible, including support jobs that can be named default:, by checking for the existence of a script: section. Configuration options defined out of the default context will still be honored.

  1. This allows to properly discover the:
# a default that is CI job
default:
  script: My CI job
  1. And to discover the:
# a default configuration, as it is missing script:
default:
  variables:
    KEY: VALUE1
  1. And to properly translate (for backward compatiblity):
variables:
  KEY: VALUE1
  1. And handle the case as such:
variables:
  KEY: VALUE1

default:
  variables: # This variables: take precedence, making the KEY2:VALUE2 the only value
    KEY2: VALUE2
Edited by Jason Yavorsky