How do `include` and `extends` help reuse configuration?
IntermediateConceptGitLab CI
Answer
include pulls in YAML from local files, other projects, remote URLs or GitLab templates. extends makes a job inherit from a hidden job (name starts with a dot), merging keys. Anchors (&/*) also work within a file.
include:
- project: platform/ci-templates
ref: v2.1.0
file: /templates/docker-build.yml
- template: Security/SAST.gitlab-ci.yml
.deploy-base:
image: bitnami/kubectl:1.31
before_script: [kubectl config use-context $KUBE_CONTEXT]
deploy-staging:
extends: .deploy-base
script: [kubectl apply -f k8s/]
More on GitLab CI
How does GitLab CI/CD work at a high level?BeginnerWhat is a GitLab Runner and what executors exist?IntermediateWhat are the types of runners (shared, group, project) and tags?IntermediateHow do `rules:` work and how do they replace `only/except`?IntermediateWhat are workflow rules and how do they prevent duplicate pipelines?AdvancedHow do artifacts and cache differ in GitLab CI?Intermediate