DevOps / Gitlab Interview questions
What is the difference between "include" and "extends" in GitLab CI/CD YAML?
include pulls in an entire external .gitlab-ci.yml file (local, from another project, a remote URL, or a CI/CD component) and merges its contents into the current pipeline definition, useful for sharing whole sets of jobs or templates across projects.
extends works within a single resolved configuration: it lets one job inherit the keys of another job (or hidden template job, usually prefixed with a dot like .base_job), then override or add specific keys, similar to inheritance between classes.
.base_test: image: node:20 script: - npm install unit-tests: extends: .base_test script: - npm run test:unit include: - project: 'my-group/ci-templates' file: '/security-scans.yml'
In short: include brings in files; extends reuses job definitions within the final merged file. They're often used together, including a shared template file and then extending one of the hidden jobs it defines to customize it for a specific project.
More Related questions...