Real-Time GitLab CI/CD Interview Questions (2027)

52 real-time GitLab CI/CD interview questions with YAML to read and fix: rules, workflow, needs, artifacts, cache, includes, components and OIDC.

Sep 17, 2025 - 14:24
Nov 6, 2026 - 22:43
 0  139
Real-Time GitLab CI/CD Interview Questions (2027)

Real-time GitLab CI/CD interview questions put a piece of .gitlab-ci.yml in front of you and ask what it does, why a job did or did not run, or how you would change it. You need to read rules, needs, artifacts, cache, variables and includes quickly and explain the result in plain words. This page has 52 questions built around YAML snippets, grouped by experience level.

Keywords and behaviour were checked against the GitLab CI/CD YAML reference on docs.gitlab.com in November 2026. Some features depend on your GitLab tier or version; those answers say so.

Key takeaways

  • Many GitLab interviews now include a "read this YAML" round. Practise predicting which jobs run on a push, a merge request and a schedule.
  • rules are evaluated top to bottom and the first match wins. Most wrong answers come from forgetting that.
  • Know the difference between what a job inherits from default, from extends and from !reference.
  • Artifacts pass files between jobs in one pipeline. Cache speeds up repeated downloads and may be missing. Mixing them up is a common mistake.
  • Senior rounds ask you to review a pipeline for speed, safety and reuse: needs, interruptible, resource_group, protected variables and CI/CD components.
  • For each snippet, say what runs, when, and what could go wrong.

How this page fits with our other GitLab guides

Our 90+ GitLab CI/CD interview questions guide is the main reference and explains each concept. The scenario-based GitLab CI/CD questions page covers operational incidents such as runner outages, leaked credentials and migrations. This page sits between them: every question gives you configuration to read or write, the way a live technical round does. For full working pipelines, see our 15 GitLab CI/CD pipeline examples.

Snippet topicWhat interviewers checkQuestions
Stages, jobs, scriptOrder of execution, defaults1 to 8
Rules and workflowWhich pipeline type runs which job9 to 18, 27 to 31
Artifacts, cache, needsData flow and speed19 to 26, 32 to 36
Reuse and includesMaintainability37 to 42
Fix-this-YAMLDebugging under time pressure43 to 52

Read-the-YAML questions for freshers

1. In what order do these jobs run?

stages: [build, test, deploy]

lint:
  stage: test
  script: npm run lint

compile:
  stage: build
  script: npm run build

unit:
  stage: test
  script: npm test

compile runs first because it is in build. When it succeeds, lint and unit run in parallel in test, if enough runners are free. No job is in deploy, so that stage is skipped. Order in the file does not matter; the stage does.

2. Which stage does this job run in?

hello:
  script: echo "hi"

test. A job with no stage keyword goes into the test stage. If the file has no stages list, the defaults are .pre, build, test, deploy and .post.

3. What happens if compile fails in question 1?

Jobs in later stages do not start, so lint and unit are skipped, and the pipeline is marked failed. The exception is a job that uses when: on_failure or when: always, or a job that does not depend on the failed one through needs.

4. What does this default block do?

default:
  image: node:20
  before_script:
    - npm ci
  retry: 1

Every job uses the node:20 image, runs npm ci before its script and retries once on failure, unless the job sets its own value. A job that sets before_script replaces the default one rather than adding to it.

5. What is the difference between these two variable definitions?

variables:
  APP_ENV: staging

deploy:
  variables:
    APP_ENV: production
  script: echo $APP_ENV

The top-level APP_ENV applies to all jobs. The job-level one overrides it for deploy, which prints production. Variables set in project or group CI/CD settings take priority over both, which matters when a value seems to be ignored.

6. What does after_script do here, and when does it run?

test:
  script: ./run-tests.sh
  after_script:
    - ./collect-logs.sh

after_script runs after script, including when script fails. It runs in a separate shell, so variables exported in script are not available. Its own failure does not change the job's result. It also runs when a job is cancelled while running, in current GitLab versions.

7. What does this job produce, and how long is it kept?

build:
  script: npm run build
  artifacts:
    paths: [dist/]
    expire_in: 1 week

It uploads the dist/ folder as a job artifact that jobs in later stages download automatically. GitLab deletes it after one week. The artifacts from the latest successful pipeline on a branch are kept by default even after expiry, unless that setting is turned off.

8. What does when: manual mean here?

deploy_prod:
  stage: deploy
  script: ./deploy.sh prod
  when: manual

The job waits for someone with permission to click play. A manual job outside rules has allow_failure: true by default, so the pipeline can show as passed while the deploy has not run. Many teams add allow_failure: false to make the pipeline wait.

9. On which pipelines does this job run?

docs:
  script: make docs
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH

Only on branch pipelines for the default branch, usually main. In merge request pipelines CI_COMMIT_BRANCH is not set, so the rule does not match and the job is not added.

10. What does this rule list do for a merge request?

test:
  script: npm test
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
    - if: $CI_COMMIT_TAG
      when: never
    - when: on_success

In a merge request pipeline the first rule matches, so the job runs. For a tag pipeline, the second rule matches and the job is excluded. For any other pipeline, such as a branch push, the last rule adds the job. Rules stop at the first match.

11. Will this job run when only README.md changed in a merge request?

backend_tests:
  script: go test ./...
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
      changes:
        - "api/**/*"
        - go.mod

No. Both conditions in the rule must match, and no listed file changed. In merge request pipelines GitLab compares against the target branch, so the check is reliable there.

12. What does exists do?

docker_build:
  rules:
    - exists:
        - Dockerfile
  script: docker build -t app .

The job is added only if a Dockerfile is present in the repository at that commit. It is common in shared templates that many projects include.

13. What does this workflow block decide?

workflow:
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
    - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
      when: never
    - if: $CI_COMMIT_BRANCH

It controls whether a pipeline is created at all. It runs merge request pipelines, skips a branch pipeline when that branch has an open merge request, and otherwise runs branch pipelines. This pattern stops duplicate pipelines on every push to an MR branch.

14. Which predefined variables tell you why a pipeline started?

CI_PIPELINE_SOURCE. Common values are push, merge_request_event, schedule, web (Run pipeline button), api, trigger, pipeline (multi-project) and parent_pipeline (child pipelines).

15. What does this job do on a schedule?

nightly_scan:
  script: ./scan.sh
  rules:
    - if: $CI_PIPELINE_SOURCE == "schedule" && $SCAN_TYPE == "full"

It runs only in scheduled pipelines where the schedule defines SCAN_TYPE=full. This lets one project have several schedules (nightly full scan, hourly quick check) that run different jobs.

16. How do you read a regex condition in rules?

rules:
  - if: $CI_COMMIT_BRANCH =~ /^release\/.+$/

The job runs on branches whose name starts with release/. GitLab uses RE2 syntax, and !~ means does not match.

17. What does allow_failure with exit codes do?

audit:
  script: npm audit --audit-level=high
  allow_failure:
    exit_codes: [1]

If the script exits with code 1, the job shows a warning and the pipeline continues. Any other non-zero exit code still fails the job.

18. What is wrong with mixing only and rules in one job?

GitLab rejects it: rules cannot be used together with only or except in the same job. only and except are not actively developed, so new configuration should use rules.

Write-the-YAML questions for 2 to 5 years of experience

19. Make unit start as soon as compile finishes, without waiting for lint.

unit:
  stage: test
  needs: [compile]
  script: npm test

needs builds a directed acyclic graph. The job starts when compile succeeds and only downloads artifacts from the jobs it needs.

20. A job does not use any earlier artifacts. How do you stop it downloading them?

security_lint:
  stage: test
  dependencies: []
  script: ./lint-iac.sh

An empty dependencies list downloads nothing. With needs, use needs: [] to start immediately with no artifacts, or needs: [{job: compile, artifacts: false}] to wait without downloading.

21. Write a cache that only changes when the lock file changes.

default:
  cache:
    key:
      files:
        - package-lock.json
    paths:
      - .npm/
  before_script:
    - npm ci --cache .npm --prefer-offline

The key is a hash of package-lock.json, so a new cache is created only when dependencies change. Caching node_modules directly is possible but larger and more fragile.

22. How do you stop most jobs from uploading the cache they only read?

test:
  cache:
    key:
      files: [package-lock.json]
    paths: [.npm/]
    policy: pull

policy: pull downloads but never uploads, which saves time. One job, often a dedicated install job, uses pull-push or push to refresh it.

23. Publish JUnit results so they show in the merge request.

test:
  script: npm test -- --reporters=jest-junit
  artifacts:
    when: always
    reports:
      junit: junit.xml

when: always uploads the report even when tests fail, which is when you need it most. The merge request widget then lists failed tests.

24. Show coverage in the merge request.

test:
  script: npm test -- --coverage
  coverage: '/Lines\s*:\s*(\d+\.?\d*)%/'
  artifacts:
    reports:
      coverage_report:
        coverage_format: cobertura
        path: coverage/cobertura-coverage.xml

The coverage regex reads the percentage from the job log. The Cobertura report adds line-by-line coverage in the merge request diff.

25. Run tests against three Node versions with one job definition.

test:
  image: node:$NODE_VERSION
  parallel:
    matrix:
      - NODE_VERSION: ["18", "20", "22"]
  script: npm test

parallel:matrix creates three jobs, one per value. Other jobs can needs a specific one with parallel:matrix in the needs entry.

26. Split a slow test suite across five jobs.

rspec:
  parallel: 5
  script: bundle exec rspec $(./split-tests.sh $CI_NODE_INDEX $CI_NODE_TOTAL)

parallel: 5 creates five copies and sets CI_NODE_INDEX (1 to 5) and CI_NODE_TOTAL. Your script uses them to choose its share of tests.

27. Deploy to production only from tags that look like versions.

deploy_prod:
  stage: deploy
  script: ./deploy.sh "$CI_COMMIT_TAG"
  environment:
    name: production
    url: https://app.example.com
  rules:
    - if: $CI_COMMIT_TAG =~ /^v\d+\.\d+\.\d+$/
      when: manual

The job appears only in tag pipelines for tags such as v2.4.1, and waits for a click. Inside rules, a manual job does not default to allow_failure: true, so the pipeline waits. Protect the tag pattern in project settings so only maintainers can create such tags.

28. Make sure two production deploys never run at the same time.

deploy_prod:
  resource_group: production
  script: ./deploy.sh

Jobs that share a resource_group run one at a time across pipelines. The process mode (for example oldest first) can be changed through the API.

29. Cancel old pipelines when a newer commit is pushed.

default:
  interruptible: true

deploy_prod:
  interruptible: false

With the project setting "Auto-cancel redundant pipelines" on, jobs marked interruptible: true in an older pipeline are cancelled when a new pipeline starts on the same branch. Deploy jobs are set to false so a half-finished deploy is not cut off.

30. Create a review app per merge request and remove it when the MR closes.

review:
  script: ./deploy-review.sh "$CI_COMMIT_REF_SLUG"
  environment:
    name: review/$CI_COMMIT_REF_SLUG
    url: https://$CI_COMMIT_REF_SLUG.review.example.com
    on_stop: stop_review
    auto_stop_in: 3 days
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"

stop_review:
  script: ./delete-review.sh "$CI_COMMIT_REF_SLUG"
  environment:
    name: review/$CI_COMMIT_REF_SLUG
    action: stop
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
      when: manual

on_stop links the stop job, which GitLab runs when the branch is deleted or the environment is stopped. auto_stop_in cleans up forgotten environments.

31. Run a job on a delay after another stage.

smoke_after_rollout:
  stage: verify
  when: delayed
  start_in: 10 minutes
  script: ./smoke.sh

The job starts 10 minutes after the previous stage finishes. Useful when a rollout needs time before checks make sense.

32. Trigger a child pipeline from a generated file.

generate:
  stage: build
  script: ./gen-pipeline.sh > child.yml
  artifacts:
    paths: [child.yml]

run_child:
  stage: test
  trigger:
    include:
      - artifact: child.yml
        job: generate
    strategy: depend

The child pipeline runs the generated jobs. strategy: depend makes the trigger job wait for and mirror the child's status.

33. Trigger a pipeline in another project and pass a variable.

deploy_infra:
  trigger:
    project: platform/infra
    branch: main
  variables:
    APP_VERSION: $CI_COMMIT_SHORT_SHA

This is a multi-project pipeline. The user who runs the upstream pipeline needs permission to run pipelines in platform/infra.

34. Authenticate to a cloud provider without stored keys.

deploy:
  id_tokens:
    CLOUD_OIDC_TOKEN:
      aud: https://iam.example.com
  script:
    - ./exchange-token-and-deploy.sh "$CLOUD_OIDC_TOKEN"

id_tokens creates a signed JWT for this job. The cloud provider trusts GitLab as an OIDC identity provider and limits which project, branch or environment can assume the role, through claims such as project_path and ref.

35. Create a GitLab release from a tag pipeline.

release:
  image: registry.gitlab.com/gitlab-org/release-cli:latest
  rules:
    - if: $CI_COMMIT_TAG
  script: echo "Releasing $CI_COMMIT_TAG"
  release:
    tag_name: $CI_COMMIT_TAG
    description: "Release $CI_COMMIT_TAG"

The release keyword creates a release on the tag. Newer runners can use the glab CLI image instead of release-cli; check the release keyword docs for your GitLab version.

36. Keep failed job files for debugging only.

e2e:
  script: npx playwright test
  artifacts:
    when: on_failure
    paths: [test-results/]
    expire_in: 3 days

Screenshots and traces upload only when the job fails, which saves storage on green runs.

Review-the-pipeline questions for senior engineers

37. What does extends do here, and what is merged?

.deploy_base:
  image: alpine:3.20
  script: ./deploy.sh
  variables:
    REGION: ap-south-1

deploy_staging:
  extends: .deploy_base
  variables:
    TARGET: staging

deploy_staging gets the image and script, and the hashes are merged, so it has both REGION and TARGET. Arrays such as script are replaced, not merged. A job name starting with a dot is hidden and does not run.

38. When would you use !reference instead of extends?

.setup:
  script:
    - ./install-tools.sh

test:
  script:
    - !reference [.setup, script]
    - make test

When you need part of another job, such as its script lines, combined with your own. extends would replace the script array instead.

39. What does each include type do?

include:
  - local: ci/test.yml
  - project: platform/ci-templates
    ref: v3.2.0
    file: /templates/docker.yml
  - template: Jobs/SAST.gitlab-ci.yml
  - component: $CI_SERVER_FQDN/platform/components/[email protected]
    inputs:
      stage: test

local is a file in the same repo, project a file in another project at a fixed ref, template a GitLab-provided template, and component a versioned CI/CD component with typed inputs. In review I would ask for fixed refs or versions, not a moving branch, so a change upstream cannot alter our pipeline silently.

40. How do you define inputs in your own component or included file?

spec:
  inputs:
    stage:
      default: test
    image:
      default: node:20
---
lint:
  stage: $[[ inputs.stage ]]
  image: $[[ inputs.image ]]
  script: npm run lint

The spec header declares inputs, and $[[ inputs.name ]] interpolates them when the file is included. Inputs are resolved at pipeline creation, unlike variables, which are expanded at run time.

41. You are reviewing a 40-minute pipeline. What do you look for in the YAML?

Jobs waiting on stages they do not need (add needs), caches keyed on the commit (use lock file keys), jobs downloading every artifact (dependencies: []), large Docker images pulled each run, tests not split with parallel, full clones where GIT_DEPTH would do, and jobs running on every change that could use rules:changes. Pipeline analytics and job durations show where to start.

42. What security problems would you flag in this job?

deploy:
  image: someuser/deploy-tools:latest
  script:
    - curl -s https://example.com/install.sh | bash
    - echo "token=$PROD_TOKEN"
    - ./deploy.sh

An unpinned third-party image, piping a remote script into bash, and printing a secret to the log. I would ask for a pinned image by digest from a trusted registry, a reviewed install step, a masked and protected PROD_TOKEN (or OIDC instead of a token), and rules that limit the job to protected branches or tags.

Fix-this-YAML scenario questions

These are the live-debugging part of a real-time round. Say what is wrong, then show the corrected lines.

43. GitLab says "jobs:build config should implement a script: or a trigger: keyword". Why?

build:
  stage: build
  scripts:
    - make

The keyword is misspelled as scripts. It must be script. The pipeline editor's validation and the CI Lint tool catch this before you push.

44. A job that should run on main never runs. Find the bug.

deploy:
  rules:
    - when: on_success
    - if: $CI_COMMIT_BRANCH == "main"
      when: manual

It actually runs everywhere automatically, because the first rule has no condition and always matches. Rule order matters. Put the if rule first, and remove the catch-all if the job should run only on main.

45. The test job fails with "dist: No such file or directory". Why?

build:
  stage: build
  script: npm run build

test:
  stage: test
  script: ls dist/

The build job does not declare artifacts, so dist/ is lost when its container stops. Add artifacts: paths: [dist/] to build. Cache is not the fix, because cache is not guaranteed to be present.

46. This YAML fails to parse. Why?

test:
  script:
    - echo "Result: ok"
    - echo Status: done

The second line is an unquoted string containing : , which YAML reads as a mapping. Quote the whole command: - 'echo Status: done'. The first line is fine because it is already quoted.

47. A variable from settings prints as empty on a feature branch but works on main. Why?

The variable is marked Protected, so it is only passed to pipelines on protected branches and tags. Either protect the branch, create a separate unprotected variable for non-production values, or limit the job to protected refs with rules.

48. A job that uses needs: [lint] fails pipeline creation with "job needs lint which is not in any previous stage" or "does not exist". What happened?

lint was not added to this pipeline, usually because its own rules excluded it. Use needs: [{job: lint, optional: true}] if the dependency is sometimes absent, or align the rules of both jobs.

49. Docker builds fail with "Cannot connect to the Docker daemon". The job is below.

build_image:
  image: docker:27
  script:
    - docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA .

There is no daemon. Add the docker:27-dind service and the TLS variables that the GitLab docs describe, on a runner configured for privileged mode, or switch to a daemonless builder such as Buildah if your runner policy forbids privileged containers. Also log in with CI_REGISTRY_USER and CI_REGISTRY_PASSWORD before pushing.

50. The deploy job runs even when the test job failed. Why?

deploy:
  stage: deploy
  when: always
  script: ./deploy.sh

when: always runs the job regardless of earlier failures. Use the default on_success. Keep always for cleanup or notification jobs.

51. The included template changed and broke every pipeline overnight. What is wrong in this include?

include:
  - project: platform/ci-templates
    file: /templates/build.yml

No ref, so it follows the template project's default branch. Pin it to a tag such as ref: v3.2.0, or move to CI/CD components with semantic versions, and upgrade on purpose.

52. A merge request pipeline shows the job twice, once as "detached". What is the cause?

test:
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
    - if: $CI_COMMIT_BRANCH

Each push creates a branch pipeline and a merge request pipeline, and the job matches both. Add the workflow:rules from question 13, or use the built-in Workflows/MergeRequest-Pipelines.gitlab-ci.yml template, so only one pipeline type is created.

How to practise for a real-time round

  1. Create a free project on GitLab.com and enable a shared or your own runner.
  2. Paste each snippet above into the pipeline editor and use the "Validate" tab to simulate a pipeline on a branch.
  3. Predict which jobs appear for a push, a merge request and a tag, then check.
  4. Break things on purpose: wrong rule order, missing artifacts, protected variable on a feature branch.
  5. Time yourself explaining a 60-line pipeline in under three minutes.

Related reading: 15 GitLab Runner optimization tips, 10 GitLab CI/CD secrets used by DevOps experts and the 200+ DevOps interview questions guide. For instructor-led labs, the GitLab training course runs in our Kharadi, Pune classroom and live online.

FAQs

What is a real-time GitLab CI/CD interview question?

It is a question where you read or write actual .gitlab-ci.yml configuration and explain what happens, instead of defining a term. Many interviewers share a screen with a pipeline file and ask you to predict or fix its behaviour.

How are GitLab rules evaluated?

Top to bottom. The first rule whose conditions match decides whether the job is added and with which when value. If no rule matches, the job is not added.

What is the difference between needs and dependencies?

needs changes when a job starts and which artifacts it fetches. dependencies only controls which artifacts are downloaded and keeps stage order.

Why does my protected variable come through empty?

Protected variables are only exposed to pipelines on protected branches or tags. On an unprotected feature branch the variable is not set.

Should I use extends or CI/CD components?

Use extends for reuse inside one project. Use CI/CD components, published in a catalog with versions and inputs, for reuse across many projects.

How do I check a pipeline file before pushing?

Use the pipeline editor, which validates as you type and can simulate a pipeline, or the CI Lint tool under Build, Pipeline editor. The glab ci lint command does the same from a terminal.

Official references

What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Angry Angry 0
Sad Sad 0
Wow Wow 0
Mridul I am a passionate technology enthusiast with a strong focus on DevOps, Cloud Computing, and Cybersecurity. Through my blogs at DevOps Training Institute, I aim to simplify complex concepts and share practical insights for learners and professionals. My goal is to empower readers with knowledge, hands-on tips, and industry best practices to stay ahead in the ever-evolving world of DevOps.