Skip to content
Tutorials Center
My learning

Topics

Lesson 43 of 44 ยท Practice and Review

CI/CD Interview Questions

Prepare for CI/CD interviews with answers on concepts, GitHub Actions, Jenkins, GitLab, pipeline security, deployment strategies and real scenarios.

CI/CD interviews rarely ask you to recite syntax. They ask whether you understand why pipelines exist, what makes them fast and safe, and how you would react when one breaks at the worst moment. Good answers are short, concrete and honest about trade-offs. This lesson collects the questions that come up most often, grouped by topic, with answers you can adapt to your own words.

Use it as a revision list: cover the answer, say yours out loud, then compare. Each answer points to the lesson where the topic is taught in full. Everything here is explanation and read-only configuration, because the real tools need a server or an account. Two small stand-in demos at the end let you see a few answers in action; they are models written for this lesson, not the real products.

Concepts

What is the difference between continuous integration, continuous delivery and continuous deployment? Continuous integration means every change is merged into the shared branch often and verified automatically by a build and tests. Continuous delivery means every change that passes is always in a releasable state, and a human decides when to ship. Continuous deployment removes that human step: every passing change goes to production automatically. See What Is CI/CD?.

Why is a fast pipeline so important? Feedback speed decides behavior. A pipeline that takes five minutes is checked before the developer switches task; one that takes an hour is ignored, batched or bypassed. Slow pipelines also encourage large changes, which are harder to review and riskier to ship. See Making Pipelines Fast.

What does "fail fast" mean in a pipeline? Order the checks so the cheapest and most likely to fail run first (formatting, linting, unit tests) and expensive ones (end-to-end tests, deployments) run only after those pass. A failure then costs seconds instead of minutes.

What decides whether a step passes or fails? Its exit code. Zero means success; any other value means failure, and by default the job stops at the first failing step. Tools that print errors but exit with zero will not stop a pipeline, which is a classic bug. See Anatomy of a Pipeline.

What is the difference between an artifact and a cache? An artifact is an output you want to keep or pass on: a build, a test report, a package. A cache is an optimization that speeds up later runs, such as downloaded dependencies, and the pipeline must still work if the cache is empty. See Caching and Artifacts.

What is "build once, deploy many"? Build one artifact (for example a container image tagged with the commit SHA) and promote that same artifact through staging and production. Rebuilding per environment means you deploy something different from what you tested.

GitHub Actions

What are the main parts of a workflow file? A workflow lives in .github/workflows/, has a trigger (on), one or more jobs, each job runs on a runner (runs-on) and contains steps that either run commands (run) or use a packaged action (uses). See Your First Workflow.

How do jobs depend on each other? Jobs run in parallel by default. needs: [build] makes a job wait for another and lets it read that job's outputs. If a needed job fails, the dependent job is skipped unless you override it with an if condition such as always(). See Jobs, Steps and Dependencies.

What is a matrix build and when would you not use one? A matrix runs the same job over combinations of values, such as Node 20 and 22 on two operating systems. Do not use it when combinations add cost without finding bugs, for example testing every minor version of a language when you only support two. exclude, include and fail-fast keep it manageable. See Matrix Builds.

What is the difference between vars and secrets? vars hold non-sensitive configuration and appear in plain text. secrets are stored encrypted and masked in logs. Masking is exact text matching, so a secret that is transformed before printing can still leak. See Secrets, Variables and Environment Variables.

What is GITHUB_TOKEN and how do you limit it? It is a short-lived token created for each run. Set permissions explicitly, starting from contents: read; once you write the block, unlisted scopes drop to none.

How do you stop two deploys from running at once? Use a concurrency group, for example group: deploy-production. For deploys, leave cancel-in-progress off so a running deployment is not interrupted halfway; for pull request checks, turn it on to cancel outdated runs.

What is a reusable workflow? A workflow with an on: workflow_call trigger, declared inputs and secrets, that other workflows call with uses: at the job level. It removes duplicated pipelines across repositories. A composite action does the same for a sequence of steps inside one job. See Reusable Workflows and Composite Actions.

Jenkins

How is Jenkins structured? A controller stores configuration, schedules builds and serves the UI. Agents (nodes) execute the work. Plugins add integrations. You should keep builds off the controller so a bad build cannot take down the scheduler. See Jenkins: Controller, Agents and Jobs.

Declarative or scripted pipeline? Declarative has a fixed structure (pipeline, agent, stages, post) that is easy to read and validate, and it covers most projects. Scripted pipelines are plain Groovy and allow arbitrary logic, at the cost of readability. A common approach is declarative with small script blocks, and shared libraries for repeated logic. See The Declarative Jenkinsfile.

What is the purpose of the post section? It runs after the stages according to the result: always, success, failure, unstable, cleanup. It is where you archive reports, send notifications and clean the workspace.

How do you handle credentials in Jenkins? Store them in the credentials store and bind them with withCredentials so they exist only inside that block and are masked in the console. Never hard-code them in the Jenkinsfile. See Agents, Docker Agents and Credentials.

GROOVY
withCredentials([string(credentialsId: 'registry-token', variable: 'TOKEN')]) {
  sh 'echo "$TOKEN" | docker login ghcr.io -u ci --password-stdin'
}

What is a multibranch pipeline? A job type that scans a repository and creates a pipeline per branch or pull request that contains a Jenkinsfile, and removes them when branches disappear.

GitLab CI/CD

What is in .gitlab-ci.yml? A list of stages and jobs. Each job has a stage, a script and optional image, variables, rules, cache, artifacts and needs. Jobs in one stage run in parallel; stages run in order. See GitLab CI/CD Basics.

What does needs do? It builds a directed acyclic graph: a job starts as soon as the jobs it needs are done, even if earlier stages are still running for other jobs. This shortens pipelines compared with strict stage order. See Rules, needs, Artifacts and Cache.

Why prefer rules over only/except? rules are more expressive (conditions on variables, changed files, and per-rule settings such as when) and are the maintained approach. only/except are legacy keywords and should not be mixed with rules in a job.

How do you reuse configuration? include pulls in other files or templates, extends inherits from another job (often a hidden job starting with a dot), and !reference copies a specific part of a job. See Includes, Templates and Environments.

Security

What is script injection in a workflow? Putting untrusted text, such as a pull request title, directly into a shell script through ${{ ... }}. GitHub replaces the expression before the shell runs, so a crafted title can become commands. The fix is to pass it through an environment variable and use "$VAR".

YAML
# Risky: the title becomes part of the script text
- run: echo "${{ github.event.pull_request.title }}"

# Safer: the title stays data
- run: echo "$TITLE"
  env:
    TITLE: ${{ github.event.pull_request.title }}

Why pin third-party actions to a commit SHA? A tag can be moved to different code. A full commit SHA cannot, so you review exactly what will run. Tools such as Dependabot can still propose updates. See Securing Your Pipeline.

Why is pull_request_target dangerous? It runs with the base repository's secrets and write token. If it also checks out and runs the pull request's code, an outsider's code runs with your privileges. Use pull_request for untrusted code, or keep pull_request_target workflows from executing anything from the branch.

What are OIDC tokens and why use them for deployment? The pipeline asks the cloud provider to trust a short-lived identity token that describes the repository, branch and environment, and exchanges it for temporary credentials. There is no long-lived key to store, leak or rotate. See Environments, Approvals and Deployments.

Deployment strategies

Compare rolling, blue-green and canary.

Strategy How it works Strength Cost
Rolling Replace instances a few at a time No extra capacity needed Two versions run together; rollback is another rollout
Blue-green Deploy to an idle copy, then switch traffic Instant switch and rollback Double the capacity during release
Canary Send a small share of traffic to the new version Real-traffic validation, small blast radius Needs good metrics and routing

See Deployment Strategies.

How do you handle database changes with zero downtime? Use expand and contract: first add new columns or tables in a backward-compatible migration, deploy code that works with both shapes, migrate the data, and only later remove the old structure. Old and new application versions must both run against the schema during the rollout.

What is a feature flag and how does it relate to deployment? A runtime switch that separates deploying code from releasing a feature. You can ship unfinished work dark, enable it for a few users and turn it off without a redeploy.

Scenario questions

Scenario: the pipeline became slow, 25 minutes. What do you do? Measure first: find the critical path, the longest chain of dependent jobs. Then cache dependencies, run independent jobs in parallel, split the slowest test suite, skip jobs whose files did not change, and use a smaller base image. Re-measure after each change.

flowchart TD
  A["Pipeline is slow"] --> B["Measure per job<br/>and find the critical path"]
  B --> C{"Is the time spent<br/>installing or waiting?"}
  C -->|"Installing"| D["Add caching,<br/>smaller images"]
  C -->|"Waiting in a queue"| E["Add runners,<br/>reduce job count"]
  C -->|"Running tests"| F["Split and parallelize,<br/>skip unaffected work"]
  D --> G["Re-measure"]
  E --> G
  F --> G

Diagnose before optimizing: the fix depends on where the time actually goes.

Scenario: a test fails once in ten runs. What now? Do not just add retries and forget. Record the flaky test, find the cause (shared state, timing, ordering, an external service), fix or quarantine it with a ticket and an owner, and track the flake rate. Retries hide the problem and make the suite slower.

Scenario: production broke right after a deploy. Roll back first, investigate second. A good pipeline can redeploy the previous artifact in minutes, which is another reason to keep versioned, immutable artifacts. Afterward, write down what the pipeline failed to catch and add a test or a smoke check.

Scenario: a secret appeared in a log. Treat it as compromised: revoke and rotate it immediately, delete or redact the log if possible, find how it was printed and fix the cause. Masking is not a substitute for rotation.

Scenario: you maintain a monorepo with 30 packages and every change runs everything. Detect affected packages from the changed files and the dependency graph, then build and test only those, using path filters or a dynamic matrix. See CI for Monorepos.

Stand-in: fail fast saves time

This model compares two stage orders for a change that has a lint error. Times are made up. It shows why cheap checks go first.

JS Cost of a failure by stage order

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The same broken change gives feedback after 1 minute in one order and 26 minutes in the other.

Stand-in: a canary decision

A canary compares the new version's error rate with the old one and decides whether to continue or roll back. This is a simplified model of that rule, not a real deployment tool.

JS Canary promote or roll back

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What is the key difference between continuous delivery and continuous deployment?

    Both keep every passing change releasable. Continuous deployment also ships it to production automatically, while continuous delivery waits for a human decision.
  2. 2. A pipeline step prints errors but the job stays green. What is the most likely cause?

    Pass and fail are decided by exit codes. A tool that reports problems but returns zero does not stop the job.
  3. 3. Why is passing a pull request title through an environment variable safer than writing the expression inside the script?

    GitHub substitutes expressions before the shell runs, so crafted text can become commands. An environment variable is read by the shell as plain data.
  4. 4. Which strategy needs double capacity during a release but gives an instant rollback by switching traffic back?

    Blue-green keeps the old environment running while the new one is verified, so traffic can switch back immediately.
  5. 5. A flaky test fails one run in ten. What is the best response?

    Retries hide the problem and slow the suite. Treat a flaky test as a defect with an owner and a deadline.

Summary

  • Explain CI, continuous delivery and continuous deployment precisely, and why fast, fail-fast pipelines change how teams work.
  • Know the vocabulary of each tool: workflows, jobs and steps; controller, agents and post; stages, rules and needs.
  • Security answers center on least privilege, pinned actions, no untrusted input in scripts, careful pull_request_target use and short-lived OIDC credentials.
  • Compare rolling, blue-green and canary by capacity, rollback speed and risk, and mention expand and contract for databases.
  • For scenarios, measure first, roll back before debugging production, rotate leaked secrets and treat flaky tests as defects.

Next: CI/CD Cheat Sheet