GitLab CI interview questions and answers for DevOps and platform engineers
GitLab CI interview questions check that you can read a .gitlab-ci.yml and predict which jobs run, in what order, on which runner. Expect stages and needs, rules and workflow rules, cache versus artifacts, protected variables, includes and extends, then senior topics such as parent-child pipelines for monorepos, runner fleets and safe deployments with environments. Interviewers want the reasoning behind each keyword, because most GitLab bugs are pipelines that run when they should not, or do not run when they should.
By Evin JohnPublished 6 min read
Who gets GitLab CI questions
GitLab is popular with companies that want source control, CI and a container registry in one product, and with teams that self-manage their own instance for compliance reasons. That makes GitLab CI a regular topic for DevOps, build and release, and platform engineering interviews. Questions about delivery strategy that apply to every tool, such as blue-green releases or test pyramids, sit on CI/CD interview questions. Here the focus is the GitLab model itself.
A typical loop has a quick round of definitions, then a pipeline file to read and debug, and for senior roles a design conversation: how would you run CI for forty services in one repository, or how would you share pipeline logic across two hundred projects without copy and paste. Some teams also ask about running and securing self-managed runners.
GitLab CI fundamentals questions
| Question | What it tests | What a strong answer shows |
|---|---|---|
| What is .gitlab-ci.yml and where does it live? | Basics | The pipeline definition at the root of the repository by default. GitLab reads it on each push, merge request or schedule and creates a pipeline of jobs from it. |
| How do stages and jobs relate? | Ordering | Jobs in the same stage run in parallel. A stage starts once every job in the stage before it has passed, unless jobs use needs to start as soon as their own dependencies finish. |
| What are runners and executors? | Execution | A runner is the agent that picks up jobs. Its executor decides how a job runs: in a shell on the host, in a Docker container, as a Kubernetes pod and so on. Tags on jobs route them to runners with matching tags. |
| Instance, group and project runners? | Runner scope | Instance runners serve every project, group runners serve one group's projects, and project runners serve specific projects. Sensitive deploy jobs often go to a dedicated runner that ordinary jobs cannot reach. |
| Cache versus artifacts? | Data | Cache is a best-effort speed-up for dependencies, shared between pipelines and allowed to go missing. Artifacts are job outputs uploaded to GitLab, passed to later jobs and downloadable, with an expiry. |
What is before_script and default? | Defaults | before_script runs before each job's script. The default keyword sets shared settings such as image, retry or before_script for every job that does not override them. |
| Name some predefined variables you use often. | Variables | CI_COMMIT_SHA, CI_COMMIT_BRANCH, CI_DEFAULT_BRANCH, CI_PIPELINE_SOURCE, CI_COMMIT_TAG, CI_REGISTRY_IMAGE and CI_JOB_TOKEN. |
| What do protected and masked mean on a CI/CD variable? | Secrets | Protected variables are only given to pipelines on protected branches and tags. Masked variables are hidden in job logs if their value meets the masking rules. Both matter; neither stops a job's own script from misusing the value. |
| How do you allow a job to fail without failing the pipeline? | Job control | allow_failure: true, usually for an advisory check. Pair it with a note on who looks at the warnings, or it becomes noise. |
What does when: manual do? | Manual jobs | The job waits for someone to start it. Common for production deploys, often combined with a protected environment so only certain people can press the button. |
A pipeline file to explain
Expect a file like this one on screen. A good habit is to walk it in the order GitLab evaluates it: workflow rules first, then each job's rules, then stages and needs.
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
when: never
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
stages: [test, build, deploy]
default:
image: node:22
interruptible: true
unit-tests:
stage: test
cache:
key:
files: [package-lock.json]
paths: [.npm/]
script:
- npm ci --cache .npm --prefer-offline
- npm test
artifacts:
when: always
reports:
junit: reports/junit.xml
build-image:
stage: build
image: docker:27
services: [docker:27-dind]
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
script:
- echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" --password-stdin "$CI_REGISTRY"
- docker build -t "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA" .
- docker push "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA"
deploy-production:
stage: deploy
needs: [build-image]
interruptible: false
resource_group: production
environment:
name: production
url: https://app.example.com
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: manual
script:
- ./scripts/deploy.sh "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA"- What do the workflow rules prevent? A push to a branch with an open merge request would otherwise create both a branch pipeline and a merge request pipeline. The middle rule drops the branch one.
- Why is the cache under `.npm/` and not `node_modules`? Cache paths must be inside the project directory, and caching the download cache keeps installs reproducible with
npm ci. - Why `artifacts: when: always` on the tests? So the JUnit report uploads even when tests fail, which is exactly when the merge request widget needs it.
- What does `resource_group` add? Only one job in the group runs at a time, so two quick merges cannot deploy over each other.
- Why is the deploy not interruptible? Auto-cancelling redundant pipelines is welcome for tests but not halfway through a production change.
- What is the trade-off of Docker-in-Docker? It needs a privileged container, which weakens isolation on shared runners. Daemonless builders or a dedicated build runner are common alternatives.
Intermediate questions
| Question | What it tests | What a strong answer shows |
|---|---|---|
Why are rules preferred over only and except? | Modern syntax | Rules are evaluated in order, the first match wins, and they combine conditions on variables, changed files and existing files. Only and except are older and cannot express as much; mixing the two in one job is not allowed. |
How does rules: changes behave on a branch's first push? | Edge cases | Without a base to compare against, changes can evaluate as true and run everything. Setting compare_to or relying on merge request pipelines makes the result predictable. |
What does needs change? | DAG | A job starts as soon as the jobs it needs finish, ignoring stage order, and only downloads artifacts from those jobs. An empty needs: [] starts a job right away. |
| include versus extends versus YAML anchors? | Reuse | include pulls in YAML from the same project, another project, a URL or a template. extends merges a hidden job such as .deploy-base into a job and works across included files. Anchors only work inside one file. |
What does !reference solve? | Reuse | It reuses a single section, such as the script or rules of another job, where extends would merge too much. |
| How do you run one job across several versions? | Matrix | parallel: matrix with a list of variable combinations creates one job per combination. Plain parallel: 4 splits a test suite across identical jobs that read CI_NODE_INDEX. |
| Parent-child versus multi-project pipelines? | Pipeline types | A child pipeline comes from a YAML file in the same project and is triggered with trigger: include, handy for monorepos or generated pipelines. A multi-project pipeline triggers another project's pipeline, for example to run integration tests owned by another team. |
What does strategy: depend do on a trigger job? | Status | The trigger job waits for the downstream pipeline and takes its status, so a failed child pipeline fails the parent. |
| What is the CI job token used for? | Job identity | CI_JOB_TOKEN lets a job call certain GitLab APIs, pull from the registry or clone other projects as the pipeline. Limit which projects accept it rather than adding personal tokens. |
| How do you get cloud credentials without stored keys? | ID tokens | Declare id_tokens with an audience in the job, and configure the cloud to trust GitLab's issuer for that project and branch. The job exchanges the token for short-lived credentials. |
.deploy-base:
image: alpine:3.20
before_script:
- apk add --no-cache curl
.mr-or-main:
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
payments:
trigger:
include: services/payments/.gitlab-ci.yml
strategy: depend
rules:
- changes: [services/payments/**/*]
notify-release:
extends: .deploy-base
rules:
- !reference [.mr-or-main, rules]
script:
- curl -fsS -X POST "$RELEASE_WEBHOOK"Senior and scenario questions
| Scenario | What it tests | What a strong answer shows |
|---|---|---|
| Every merge request runs two pipelines. | Diagnosis | Branch and merge request pipelines both match. Add workflow rules that prefer merge request pipelines when one is open, and check each job's rules for the same overlap. |
| Pipelines wait ten minutes for a runner each morning. | Capacity | Look at which tags the pending jobs need and when demand peaks. Autoscale runners, for example as Kubernetes pods or cloud instances, and split heavy jobs so they do not block quick ones. |
| A masked secret still showed up in a job log. | Incident | Rotate it first. Then find the path: base64 output, a debug flag, a value that did not meet masking rules. Move the variable to protected, narrow who can edit pipelines on protected branches, and prefer ID tokens. |
| Two hundred projects copy the same pipeline with small edits. | Standardization | Publish shared templates or reusable components from one project, pinned by version with inputs for the parts that vary, and roll new versions out gradually. |
| A forty-service monorepo runs every job on every change. | Monorepo design | Use parent-child pipelines with rules: changes per service, or generate the child pipeline from a script that inspects the diff. Keep a full run on the default branch as a safety net. |
| Shared runners run untrusted forks and production deploys. | Isolation | Separate them. Deploy jobs go to protected, tagged runners that only run for protected branches; untrusted work runs on ephemeral runners with no access to production networks. |
| Deploys got slower after the team added more checks. | Pipeline speed | Measure where time goes per job. Use needs so the image builds while slow scans run, cache wisely, mark checks that do not gate the release as non-blocking, and move long suites to scheduled pipelines. |
| How would you migrate from Jenkins to GitLab CI? | Migration | Inventory jobs, plugins and credentials, map each pattern to GitLab features, convert one representative project end to end, run both for a period, and retire old jobs only once the new pipelines have proven themselves. |
Fictional example
- Interviewer
- A developer's feature branch deployed to production last week. Here is the job: its rules begin with a
!referenceto a shared template's rules, followed by a check that the branch is main. What happened? - Candidate
- Rules are checked in order and the first match wins, so the main check only matters if nothing above it matches. I would open the merged YAML view in the pipeline editor to see the final rule list instead of guessing. My bet is that the shared rules end with a bare
when: on_successas a catch-all, so every branch matched before GitLab ever reached the main condition. The fix is to put the branch condition in the rules themselves, make production a protected environment so only certain roles can deploy, and mark the deploy variables as protected so a feature branch would not have had the credentials anyway. Then I would add a short review rule for changes to the shared template, since it affected every project that included it.
A one-week GitLab CI practice plan
- Day 1: create a project with a three-stage pipeline and read each job log. Register a runner with the Docker executor on your own machine if you can.
- Day 2: add cache and artifacts, then break the cache key and watch the job download everything again. Publish a JUnit report.
- Day 3: write workflow rules for merge request pipelines and reproduce the duplicate pipeline problem on purpose.
- Day 4: move shared settings into a hidden job, use
extendsand!reference, then split the file withinclude. - Day 5: build a parent-child pipeline for a two-service monorepo with
rules: changes, and a manual deploy job with an environment and a resource group. - Days 6 and 7: say the scenario answers out loud. For each, name what you would check first and what you would change last.
For the wider round, see DevOps engineer interview questions and Kubernetes interview questions, since many GitLab runners and deploy targets live there. If the job ad lists both tools, compare with GitHub Actions interview questions.
GitLab answers fall apart when you mix up which rule wins. Natively, an AI interview assistant for Mac and Windows, keeps a transcript of your practice rounds on your computer, so you can reread how you explained rule order and pipeline types. In practice it can also look at a screenshot of a .gitlab-ci.yml or a failed job and offer a likely cause, and on Pro or the free trial it can draw on the résumé and job description you give it. Notes from each session stay available to review.
Questions people ask
What GitLab CI questions come up in DevOps interviews?
The structure of .gitlab-ci.yml, stages versus needs, rules and workflow rules, runners and executors, protected and masked variables, cache versus artifacts, include and extends, parent-child pipelines and safe production deploys.
What is the difference between cache and artifacts in GitLab CI?
Cache is a best-effort store for dependencies shared between pipelines and may be missing. Artifacts are files a job produces, passed to later jobs and kept for download until they expire.
Why does GitLab create two pipelines for one merge request?
A push to a branch with an open merge request can match both a branch pipeline and a merge request pipeline. Workflow rules that drop branch pipelines while a merge request is open fix it.
How do I prepare for a GitLab CI interview?
Build a small project with stages, cache, artifacts, workflow rules, an include and a child pipeline, break each part on purpose, and practice explaining which rule matches first and why.
Where to go next
Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.
Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.
