DevOps / GitLab CI Basics Interview Questions
What is the 'default' keyword in GitLab CI and how does it reduce duplication?
The default keyword defines configuration that applies to all jobs in the pipeline unless overridden at the job level. It acts as a global default for common settings, reducing repetition across many jobs.
# Set defaults for all jobs default: image: ubuntu:24.04 before_script: - apt-get update -qq - echo "Setting up environment..." after_script: - echo "Job complete" retry: max: 1 when: runner_system_failure timeout: 1 hour interruptible: true # allow newer pipelines to cancel this job # Jobs inherit defaults but can override individual settings: build-job: image: node:20-alpine # overrides the default ubuntu image script: - npm ci && npm run build # before_script from default still runs python-test: # uses all defaults: ubuntu image, before_script, retry, timeout script: - pip install -r requirements.txt - pytest before_script: - pip install --upgrade pip # overrides global before_script entirely
| Keyword | Effect when set globally |
|---|---|
| image | Default Docker image for all jobs |
| before_script | Setup commands prepended to every job |
| after_script | Cleanup commands appended to every job |
| retry | Default retry behaviour for all jobs |
| timeout | Default job timeout |
| interruptible | Whether newer pipelines can cancel pending jobs |
| artifacts | Default artifact paths |
| cache | Default cache configuration |
More Related questions...