DevOps / GitLab CI Basics Interview Questions
What is the 'include' keyword and how do you share CI configuration across projects?
The include keyword lets you split pipeline configuration across multiple files or pull shared configuration from external sources. This is the foundation for sharing CI standards across many projects in an organisation.
| Type | Syntax | Use case |
|---|---|---|
| local | include: local: '/templates/jobs.yml' | Another file in the same repository |
| project | include: project: 'group/repo', file: '/ci/template.yml' | File in another GitLab project |
| remote | include: remote: 'https://example.com/ci.yml' | Any publicly accessible URL |
| template | include: template: 'Auto-DevOps.gitlab-ci.yml' | GitLab built-in templates |
# Include multiple sources include: - local: '/ci/build.yml' # file in same repo - project: 'myorg/ci-templates' # file from another project ref: main file: '/templates/deploy.yml' - template: 'SAST.gitlab-ci.yml' # GitLab built-in security template - remote: 'https://cdn.example.com/ci/lint.yml' # external URL # Using included configuration # The included files can define jobs, stages, variables, etc. # They are merged into the main .gitlab-ci.yml stages: - build - test - security - deploy # Your local jobs here, plus everything from the included files
Security note: when including files from another project with include: project, the user triggering the pipeline must have at least Reporter access to that project. Using a specific SHA hash for ref (rather than a branch name) is recommended for stability and security - branch-based refs can change.
More Related questions...