Skip to content

Interview PrepCI/CD

Designing the Pipeline ​

199. Design a CI pipeline that runs whenever a developer opens or updates a pull request. ​

The short answer

Trigger it on pull request events, and cancel older runs of the same pull request. Give it read-only permissions. Run the cheap checks first and in parallel: formatting, linting, type checking and unit checks. Then build the image without publishing it, and run security scans on the code, the dependencies, the configuration and the image. Then run integration checks against real dependencies in throwaway containers. Report every result on the pull request, and make the important jobs required for merging.

setupcheckout, cacheformatlinttype checkunit checksbuild imagenot publishedcode and secretsdependenciesimage scanintegrationall passedrequired checkFan out where work is independent, fan back in where the next step needs it.
A pull request pipeline. Four fast checks run side by side, then one image is built, then the slower checks run side by side on that image. A single summary job at the end is what the branch rules require.

In GitHub Actions:

yaml
name: pr
on:
  pull_request:
    types: [opened, synchronize, reopened]          # (1)
concurrency:
  group: pr-${{ github.event.pull_request.number }}
  cancel-in-progress: true                          # (2)
permissions:
  contents: read                                    # (3)
jobs:
  checks:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        task: [format, lint, typecheck, unit]       # (4)
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with: { node-version: 20, cache: npm }
      - run: npm ci
      - run: npm run ${{ matrix.task }}
  image:
    needs: checks                                   # (5)
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: docker/setup-buildx-action@v3
      - uses: docker/build-push-action@v6
        with:
          push: false
          load: true
          tags: checkout-api:pr
          cache-from: type=gha
      - run: trivy image --severity CRITICAL,HIGH --ignore-unfixed --exit-code 1 checkout-api:pr   # (6)
  integration:
    needs: checks
    runs-on: ubuntu-latest
    services:
      postgres:                                     # (7)
        image: postgres:16
        env: { POSTGRES_PASSWORD: ci }
        ports: ["5432:5432"]
        options: --health-cmd "pg_isready" --health-interval 5s --health-retries 10
    steps:
      - uses: actions/checkout@v4
      - run: npm ci && npm run integration
        env: { DATABASE_URL: "postgres://postgres:ci@localhost:5432/postgres" }
  all-passed:
    needs: [checks, image, integration]            # (8)
    runs-on: ubuntu-latest
    steps: [ { run: echo "all checks passed" } ]
  1. Runs when a pull request is opened, gets new commits, or is reopened.
  2. If a developer pushes again while the previous run is still going, the old run is cancelled. Nobody waits for results about code that has already changed.
  3. The job's token can only read the repository. Pull request code is not reviewed yet, so it gets the least power possible (question 271).
  4. A matrix runs the same job four times in parallel, once per task (question 248).
  5. The image build waits for the fast checks, so a formatting mistake does not waste a five-minute build.
  6. The image is built and scanned, but not pushed. Publishing happens only after merge (question 185).
  7. A service container: a real PostgreSQL running next to the job, with a health check, for integration checks (question 207).
  8. One final job that depends on all the others. The branch protection rule requires just this one job, so adding a new check later does not mean editing the branch rules.

Things this design deliberately leaves out: pushing images, deploying anywhere except optional preview environments, and any production credentials.

200. What exact steps would you place in a pipeline between code checkout and deployment? ​

The short answer

First, check out the exact commit, set up the toolchain, and restore caches. Install dependencies from the lock file. Run the static checks and the unit checks, then build. Package the image with commit tags and labels, and generate an SBOM and provenance. Scan the image, push it by digest, and sign it. Deploy it to a test environment and run integration and smoke checks there. Record everything, so the same digest can be promoted onward.

#StepWhy it is there
1Check out the exact commitEvery later step must describe this one commit
2Set up the toolchain, pinned versionsThe same compiler and runtime every time
3Restore cachesSpeed without changing results
4Install dependencies from the lock fileExact, repeatable versions
5Format, lint, type checkCheapest failures, found in seconds
6Unit checksLogic errors, found in a minute or two
7BuildThe compiled output
8Package the imageTagged with the commit, labelled with the source
9SBOM and provenanceRecords of what is inside and how it was made
10Scan the imageBlock serious, fixable vulnerabilities
11Push, and record the digestPublish once, refer to it by digest from now on
12Sign the digestProve it came from this pipeline
13Deploy to a test environmentReal configuration, real dependencies
14Integration and smoke checksProof that it works together with everything else
15Record the resultReady for promotion to the next environment

Steps 1 to 10 run on pull requests too, without pushing. Steps 11 to 15 run only after merge, on reviewed code.

Three habits that make the list trustworthy:

  1. Nothing is rebuilt later. Everything after step 11 uses the same digest.
  2. Every step fails loudly. No step quietly carries on after an error (question 203).
  3. Every step leaves evidence: logs, reports, the SBOM, the scan result, the signature. That evidence is what an auditor, or you during an incident, will need (question 196).

201. Why should fast, inexpensive checks usually run before slow, expensive tests? ​

The short answer

Because most failures are simple, and simple failures are found by cheap checks. If a missing semicolon fails in a 20-second lint step, the developer finds out in 20 seconds instead of after a 25-minute end-to-end run. Running cheap checks first gives faster feedback, wastes fewer machine minutes, frees up runners for everyone else, and keeps developers focused on the change while it is still fresh in their mind.

A worked example. A pipeline has a lint step taking 30 seconds and an end-to-end suite taking 25 minutes. Say one in five pipeline runs fails because of something lint would catch.

  • Slow first: every one of those failures costs 25 minutes and 30 seconds of waiting, plus 25 minutes of machine time.
  • Fast first: every one of those failures costs 30 seconds, and the expensive suite never starts.

Over a hundred runs a day, that is about 20 failures, which is more than eight hours of waiting and machine time saved, every day.

Why it matters beyond the numbers:

  1. Attention. A developer who gets a result in two minutes fixes it straight away. One who waits half an hour has moved on to something else, and has to switch back.
  2. Shared capacity. Runners are shared. Wasted minutes are minutes other teams' jobs spend waiting in a queue (question 266).
  3. Honest results. When the expensive suite runs, you already know the code compiles and passes basic checks. A failure there is more likely to be a real integration problem.

But do not drop the slow checks. The point is ordering, not removal. Many slow checks can also run in parallel with each other once the fast ones pass (question 202).

202. How would you decide which pipeline stages can run in parallel and which must run sequentially? ​

The short answer

Two jobs can run in parallel if neither needs the other's output and they do not fight over the same resource. A job must wait if it needs something another job produces, such as the built image, or if both would use the same thing at once, such as one shared test environment. Then weigh the cost: each parallel job needs its own runner and repeats its own setup, so parallelism only pays when the work is bigger than that setup.

Ask three questions for each pair of jobs:

  1. Does one need the other's output? Scanning the image needs the image, so scan waits for build. Linting needs nothing but the source, so it can start at once.
  2. Do they share a resource? Two jobs deploying to the same staging environment would trample each other. They must take turns, which a concurrency lock or a deployment queue enforces (question 222).
  3. Does order matter for safety? Production must not deploy before staging has been checked, even if technically it could.

If the answer to all three is no, run them in parallel.

The critical path. The slowest chain of jobs that must run one after another decides the pipeline's total time. If build takes 4 minutes, scan 2 and integration 8, and scan and integration run in parallel after build, the total is 4 + 8 = 12 minutes. Making the scan faster saves nothing. Making integration faster, or splitting it, does.

Splitting big jobs. A 20-minute check suite can be split into four parallel shards of about 5 minutes each. Tools can split by previous timing data, so shards finish at about the same time (question 224).

The cost of parallelism:

  • Each parallel job pays its own setup: start a runner, check out the code, restore caches, install dependencies. A 30-second task in its own job may spend more time on setup than on work.
  • More parallel jobs need more runners at the same moment, which costs money and can cause queueing.

A rule of thumb: combine tiny tasks into one job, and split or parallelise only the long ones.

203. How do you prevent deployment when any mandatory test or quality gate fails? ​

The short answer

Make the deploy job depend on every mandatory gate, so it cannot start unless they all succeeded. Never mark mandatory jobs as "allowed to fail" or "continue on error". Make the default fail closed, so a missing or unknown result counts as a failure. Put the same requirements on the deployment environment and on the branch, and ideally have the target itself, such as the cluster, check that the required evidence exists before accepting the image.

1. Dependencies in the pipeline.

yaml
deploy-staging:
  needs: [build, unit, integration, image-scan, policy-check]   # (1)
  if: ${{ success() }}                                          # (2)
  1. The deploy job only starts after all five succeeded.
  2. Makes the condition explicit. In GitHub Actions, jobs with needs already skip when a dependency fails, unless someone changes the condition to always(), which is a common way gates get bypassed by accident.

2. No "soft" mandatory checks. Watch for settings that turn a failure into a pass:

PlatformSetting that weakens a gate
GitHub Actionscontinue-on-error: true
GitLab CIallow_failure: true
Azure PipelinescontinueOnError: true
Shell scripts`command

Each has legitimate uses for non-mandatory jobs. On a mandatory gate, each is a hole.

3. Fail closed. If a scanner cannot reach its vulnerability database, the result is "unknown". Treat unknown as failure. A gate that passes whenever it cannot check is no gate at all.

4. Repeat the requirement where it cannot be edited away. Pipeline files can be changed in a pull request. So also require the checks in:

  • Branch protection, so nothing merges without them (question 186).
  • Environment protection, so the production environment demands its checks and approvals (question 257).

5. Verify at the target. The strongest form: the pipeline attaches signed statements, such as "scan passed", to the image, and the cluster's admission policy refuses images without them (question 147). Then even a deployment that went around the pipeline is stopped.

204. What is the purpose of linting, formatting checks, static analysis, and type checking in a CI pipeline? ​

The short answer

They are quick checks that read the code without running it, each catching a different class of problem. Formatting checks enforce one consistent layout, so reviews are about meaning, not spacing. Linting flags code patterns that are likely bugs or bad practice. Type checking proves that values are used consistently with their types. Static analysis goes deeper, following how data moves to find bugs and security flaws. All of them are cheap and run first.

CheckFindsExample toolsTypical time
FormattingInconsistent layoutPrettier, Black, gofmtSeconds
LintingLikely bugs, risky patternsESLint, Ruff, golangci-lintSeconds
Type checkingType mismatchesTypeScript tsc, mypySeconds to a minute
Static analysisDeeper bugs, security flawsCodeQL, Semgrep, SonarQubeMinutes

Formatting. A formatter rewrites code into one standard layout. In CI it runs in check mode, such as prettier --check ., and fails if any file is not formatted. The win is social: reviews never argue about tabs and spaces, and diffs show only real changes.

Linting. A linter knows hundreds of rules about risky patterns: a variable that is never used, a promise whose result is ignored, a comparison that is always true. Each one is a likely bug found in seconds.

Type checking. In TypeScript, for example:

ts
function total(prices: number[]): number {
  return prices.reduce((sum, p) => sum + p, 0)
}
total(['9.99', '5.00'])   // error: Type 'string' is not assignable to type 'number'

Without the type check, this would silently produce '09.995.00', a text joining bug, in production.

Static analysis. It follows data through the code. For example, it can see that text from an HTTP request reaches a database query without being made safe, which is a SQL injection flaw (question 214).

Why run them in CI at all if developers run them locally? Because local runs are optional and forgettable. CI makes them consistent for everyone.

205. What is the difference between unit, component, integration, contract, end-to-end, smoke, and regression tests? ​

The short answer

They differ in how much of the system each one exercises. Unit checks exercise one small piece of code alone. Component checks exercise one whole component or service, with its outside dependencies replaced. Integration checks exercise several real parts together, such as the service and its database. Contract checks confirm that two services still agree on the format of their messages. End-to-end checks exercise the whole system the way a user would. Smoke checks are a tiny set run right after a deployment. Regression is not a separate kind: it is any check that guards behaviour that used to work.

The usual picture is a pyramid: many small, fast checks at the bottom, and few large, slow ones at the top.

end-to-endintegrationcomponent and contractunithigher: slower, more realistic, costliersmoke: a few top-levelchecks after each deploy
The shape of a healthy check suite. Most checks are small and fast at the bottom. Each level up exercises more of the real system, and costs more to run and to keep reliable.
KindExercisesOutside dependenciesSpeed
UnitOne function or classReplacedMilliseconds
ComponentOne service, through its own interfaceReplacedSeconds
IntegrationSeveral real parts togetherReal, often in containersSeconds to minutes
ContractThe agreed message format between two servicesEach side checked aloneSeconds
End-to-endThe whole system as a userAll realMinutes
SmokeA few critical paths after a deployAll realSeconds to a minute
RegressionAnything that used to workAnyAny

Contract checks in a little more depth. Say web calls checkout-api. Instead of running both together, the web team writes down what it expects, for example "POST /orders returns 201 with an orderId field". The checkout-api pipeline checks that it still provides exactly that. If someone renames orderId, the provider's own pipeline fails before anything reaches production. A popular tool for this is Pact.

Smoke checks get their name from electronics: switch the new device on and see whether smoke comes out. After a deploy: does the service start, answer its health endpoint, and complete one real request?

206. Which test types should run on every pull request, on every merge to the main branch, and before production? ​

The short answer

On every pull request: everything fast and isolated, meaning formatting, linting, type checks, unit and component checks, contract checks, quick integration checks with throwaway containers, and the security scans. On every merge to main: all of that again, plus the full integration suite and a set of end-to-end checks in a shared test environment. Before production: end-to-end and smoke checks in staging, and after the production deploy, smoke checks plus continuous synthetic monitoring.

CheckPull requestMerge to mainBefore productionAfter production deploy
Format, lint, typesYesYes
Unit and componentYesYes
ContractYesYes
Integration, containersYesYes
Full integrationSometimesYes
End-to-endA small critical setYesYes, in staging
SmokePreview env, optionalYes, after deploying to devYes, in stagingYes
Security scansYesYesGate checkRescans scheduled
PerformanceRarelyNightlyBefore big releasesWatched in monitoring

The reasoning behind the table:

  1. Pull requests need speed. Developers wait for them. Keep them under about ten minutes, using only checks that need no shared environment.
  2. Main needs completeness. After merge, nobody is waiting at a keyboard, and main must stay releasable, so the full suite runs.
  3. Before production needs realism. Staging has production-like configuration and data shapes, so end-to-end checks there catch configuration and integration problems.
  4. After the deploy needs confirmation. Smoke checks prove the release is alive. Synthetic monitoring, a robot that performs a real user action every minute, such as searching and adding to the cart, keeps proving it long after the deploy.

207. How would you test an application that depends on a database, a message broker, and a third-party API? ​

The short answer

Use the real thing for what you own and can run cheaply: start a real database and a real message broker in throwaway containers for each pipeline run, apply the real migrations, and use fresh data. Replace the third-party API with a local fake server that answers like the real one, keep that fake honest with contract checks against the provider's published specification, and use the provider's sandbox for only a few end-to-end checks.

The database and the broker: run them for real.

yaml
services:
  postgres:
    image: postgres:16
    env: { POSTGRES_PASSWORD: ci }
    options: --health-cmd "pg_isready" --health-interval 5s --health-retries 10
  rabbitmq:
    image: rabbitmq:3-management
    options: --health-cmd "rabbitmq-diagnostics -q ping" --health-interval 5s --health-retries 10

Real containers catch problems fakes never would: a migration that fails on the real database version, a query that is wrong in real SQL, a message that the real broker rejects. Libraries such as Testcontainers can also start these containers from inside the check code itself.

Make each run independent: apply the real migrations at the start, create data for each check, and never share a database between parallel jobs.

The third-party API: fake it locally, check the fake.

Calling a real payment provider on every pull request causes problems: it is slow, it fails when their service hiccups, it has rate limits, it can cost money, and it can create real side effects. So:

  1. Run a fake server, such as WireMock, or a mock server generated from the provider's OpenAPI specification. It answers with realistic, recorded responses, including errors such as timeouts and declined payments.
  2. Keep the fake honest with contract checks against the provider's published specification, so if they change their API, you find out (question 205).
  3. Run a few end-to-end checks against the provider's sandbox, a test version they offer, in the main-branch pipeline or nightly, not on every pull request.

One more realism check: simulate failure. Make the fake respond slowly or with errors, and confirm your service times out, retries and degrades the way you intend.

208. When would you use mocks, fakes, service containers, or real test dependencies? ​

The short answer

Use mocks when you want to check how your code calls something, in fast unit checks. Use fakes, simple working stand-ins such as an in-memory store, when you need realistic behaviour without the real system. Use service containers when the dependency's real behaviour matters, such as a real database's SQL. Use real shared dependencies, such as a sandbox or staging, sparingly, for the final proof that everything works together.

MockFakeService containerReal dependency
What it isA stand-in that records calls and returns set answersA simple working versionThe real software, throwawayThe actual shared system
RealismLowMediumHighHighest
SpeedFastestFastSeconds to startVaries, often slow
IsolationCompleteCompletePer runShared with others
Good for"Was this called with these values?"Logic needing a working storeDatabase, broker, cache behaviourFinal end-to-end proof

Mocks check interactions. For example: "when an order is placed, the email service is asked to send exactly one receipt". The risk: if the real email service behaves differently from the mock, everything passes and production fails.

Fakes behave like the real thing in simple ways. An in-memory repository that stores and returns orders, for example, lets you check business logic quickly, without a database.

Service containers remove the guesswork for things you can run yourself (question 207). They are the main tool for integration checks.

Real dependencies come with costs: shared state with other teams, flakiness, rate limits and setup. Use them for a small number of critical end-to-end paths.

A sensible split: mocks and fakes at the bottom of the pyramid, service containers in the middle, real dependencies at the very top (question 205).

209. How should test fixtures, test data, and test credentials be managed in CI? ​

The short answer

Keep fixtures and seed data as code in the repository, created fresh for each run so runs never depend on leftovers. Never copy real production data into CI; use generated or properly masked data. Keep test credentials as CI secrets, never in the repository, give them access only to test systems, and prefer short-lived ones issued per run. Pull requests from outside contributors should get no credentials at all.

Fixtures and test data:

  1. Data as code. Seed scripts and data builders live next to the checks, reviewed like any code.
  2. Fresh for every run. A new database container per run, or a unique prefix per run, so two runs never see each other's data.
  3. Independent checks. Each check creates what it needs. A check that only passes because an earlier check left something behind is a flaky check waiting to happen (question 210).

No production data in CI:

  • It contains real people's personal information, which privacy laws such as the GDPR protect. CI logs, caches and runners are not a place for it.
  • If production-shaped data is needed, generate it, or use a properly anonymised copy where names, addresses and payment details are replaced.

Test credentials:

  1. Stored as CI secrets, never committed.
  2. Scoped to test systems. A test account with access only to the sandbox, never a production key "just for the tests".
  3. Short-lived where possible. OIDC can give each run a temporary token for a test cloud account, which expires minutes later (question 269).
  4. Not available to untrusted code. Pull requests from forks run without secrets (question 250).
  5. Rotated on a schedule, and immediately if they ever appear in a log.

Clean up afterwards, especially for anything created in shared sandboxes, so test accounts do not fill with junk and costs do not creep up.

210. How do you identify and reduce flaky tests? ​

The short answer

A flaky check passes and fails on the same code without any change. Find them by recording every check's result over time and flagging those that fail and then pass on a retry. Then fix the usual causes: fixed waits instead of waiting for a condition, checks that depend on each other's data or order, real network calls, the current date or time zone, randomness, and timing in concurrent code.

Why flaky checks are so harmful: each false failure costs a rerun, and worse, it teaches people that red means "probably nothing". Real failures then get ignored too.

Finding them:

  1. Record every result, per check, per commit. Many CI systems and add-on tools have analytics for this.
  2. Flag pass-on-retry. A check that failed and then passed on the same commit is flaky by definition.
  3. Rank by impact: how often it flakes, and how many pipelines it blocks.

The usual causes, and their fixes:

CauseFix
A fixed sleep(2) before checking a resultWait for the condition, with a timeout
Checks share data or run in a fixed orderEach check creates its own data
Calls to real external servicesFake them (question 207)
The current date, time or time zoneUse a controllable clock
Random valuesUse a fixed random seed
Timing between threads or requestsSynchronise explicitly; check eventual results
Too little CPU or memory on the runnerGive it more, or reduce parallelism
Leftover state from a previous runFresh environment per run

Do not forget the uncomfortable possibility: sometimes the flakiness is in the product, not in the check. A race condition in the code itself fails "randomly" in production too. A flaky check deserves investigation before it is dismissed.

211. Should a flaky test be automatically retried, quarantined, or treated as a release blocker, and why? ​

The short answer

It depends on what the check protects, and none of the three options should be silent. An automatic retry can reduce noise, but only if every retry is recorded, because otherwise it hides real intermittent bugs. Quarantine, moving the check out of the blocking set with an owner and a deadline, keeps the pipeline usable while it is fixed. A check that protects something critical, such as payments, stays a blocker and gets fixed immediately.

Automatic retry:

  • For: stops one unlucky run blocking everyone.
  • Against: hides real problems. A real race condition in the code shows up as "flaky, passed on retry" forever.
  • Rule: at most one retry, and every pass-on-retry is recorded and reported, so it still counts as flaky.

Quarantine:

  • Move the check into a separate, non-blocking group, which still runs and still reports.
  • Give it an owner and a deadline, such as two weeks.
  • If it is not fixed by the deadline, fix it, rewrite it, or delete it. Quarantine must not become a graveyard.
  • For: keeps the pipeline trustworthy, so red means red again.
  • Against: while quarantined, that behaviour is not protected.

Release blocker:

  • For checks guarding critical behaviour, such as money movement, security or data loss, the risk of an unprotected path is higher than the cost of a blocked pipeline.
  • Treat the flakiness as a priority bug, and fix it now.

A policy that works:

  1. One automatic retry, always recorded.
  2. A check that flakes three times in a week is quarantined automatically, with a ticket to its owner.
  3. Critical-path checks are never quarantined. They are fixed.

212. How would you enforce a code-coverage threshold without encouraging meaningless tests? ​

The short answer

Coverage only measures which lines ran, not whether anything was actually checked, so a hard global target invites checks that run code without asserting anything. Instead, require coverage on new and changed code, such as 80% of the lines in each pull request, so the number never goes backwards without forcing work on old code. Pair it with review of what the checks really assert, and, for important code, mutation testing, which measures whether the checks would notice a bug.

Why a global target goes wrong. When "90% coverage" becomes the goal, people write checks that call functions without checking the results. Coverage rises, and the code is no safer. This is an example of Goodhart's law: when a measure becomes a target, it stops being a good measure.

Better approaches:

  1. Coverage on new code. Tools such as SonarQube and Codecov can measure coverage only on the lines a pull request adds or changes. The rule "new code must be 80% covered" improves quality steadily without demanding old code be retrofitted.
  2. A ratchet. The overall number may not go down. It can go up freely. Over time it rises naturally.
  3. Sensible exclusions. Generated code, simple data definitions and start-up glue add noise to the number.

Mutation testing, the real quality measure. A tool makes small deliberate changes to your code, called mutants: it flips a > to >=, replaces a + with a -, or deletes a line. Then it runs your checks against each mutant.

  • If a check fails, the mutant was "killed": the checks noticed the bug.
  • If all checks still pass, the mutant "survived": the checks would not notice that bug in real life.

The share of killed mutants shows how much your checks really check. Tools include Stryker for JavaScript and TypeScript and PIT for Java. It is slow, so run it on critical modules or nightly, not on every pull request.

Finally, people. Reviewers should look at what checks assert, not just whether they exist.

213. How do you integrate SonarQube or a similar quality gate into a pipeline? ​

The short answer

Add a step after the build and the unit checks that runs the SonarQube scanner. It reads the source and the coverage report, and sends the analysis to the SonarQube server. The server compares the result with the project's quality gate, a list of conditions such as "no new bugs" and "80% coverage on new code". The pipeline step waits for the verdict and fails if the gate fails, and the result is shown on the pull request.

yaml
- run: npm run unit -- --coverage                       # (1)
- uses: SonarSource/sonarqube-scan-action@v5            # (2)
  env:
    SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
    SONAR_HOST_URL: ${{ vars.SONAR_HOST_URL }}
  with:
    args: >
      -Dsonar.projectKey=shop-checkout-api
      -Dsonar.javascript.lcov.reportPaths=coverage/lcov.info
      -Dsonar.qualitygate.wait=true                     # (3)
  1. The unit checks write a coverage report.
  2. The scanner analyses the code, includes that report, and uploads the results to the server.
  3. Tells the scanner to wait for the server's verdict and to fail this step if the gate fails. Without it, the pipeline would pass while the gate silently fails.

A typical quality gate, applied to new code only:

ConditionThreshold
New bugs0
New vulnerabilities0
Security hotspots reviewed100%
Coverage on new codeAt least 80%
Duplicated lines on new codeAt most 3%

Focusing on new code is SonarSource's own recommendation, often called "clean as you code". Old code improves as it is touched, and nobody is blocked by years of existing issues.

Two details worth mentioning:

  1. Pull request decoration. SonarQube can comment on the pull request itself, with the gate result and the exact lines with issues, so developers do not have to visit another site.
  2. The token is a secret, so for pull requests from forks, the scan needs special handling or runs only after review (question 250).

214. What is the difference between static application security testing (SAST), dynamic application security testing (DAST), and software composition analysis (SCA)? ​

The short answer

SAST reads your own source code without running it and looks for insecure patterns, such as user input reaching a database query unescaped. DAST attacks your running application from the outside, the way an attacker would, looking for problems such as missing security headers or injectable forms. SCA lists the third-party libraries you use and checks them against databases of known vulnerabilities and license rules. They find different problems at different stages, so mature pipelines use all three.

SASTDASTSCA
Looks atYour source codeThe running app, from outsideYour dependencies
Needs a running appNoYesNo
FindsInsecure code patternsRuntime and configuration flawsKnown CVEs, license problems
WhenEvery pull requestAgainst a test or staging deploymentEvery pull request, plus scheduled rescans
StrengthPoints to the exact lineShows what an attacker can really reachFast, precise matches
WeaknessFalse alarmsSlow; only sees what it can reachOnly knows published flaws
ExamplesCodeQL, Semgrep, SonarQubeOWASP ZAP, Burp SuiteDependabot, Snyk, Trivy

SAST is "white-box": it sees the inside. It can follow data from an HTTP request through several functions into a SQL query. It sometimes reports flows that cannot really happen, so findings need judgment.

DAST is "black-box": it sees only what an outsider sees. A tool such as OWASP ZAP crawls the app, then sends attack-like inputs to every form and endpoint. It finds things no code reading would, such as a misconfigured server, a missing Content-Security-Policy header, or a debug page left switched on.

SCA works on what you import. Most of the code in a modern app is third-party, so this is often where most findings come from (question 136). It also checks licenses: for example, it can flag a library whose license is incompatible with your product.

A fourth term you may hear: IAST, interactive testing, puts an agent inside the running app during checks, combining some of the inside view of SAST with the realism of DAST.

215. At what point should dependency, secret, container-image, and infrastructure-configuration scans run? ​

The short answer

As early as each can run, and again later because the world changes. Secret scanning runs before a commit, on every push and on every pull request. Dependency scanning runs on every pull request and on a schedule. Infrastructure and Kubernetes configuration checks run on every pull request that touches them, and again at deploy time in the cluster. Image scanning runs right after each image is built, continuously in the registry, and as a gate before deployment.

commitpull requestbuilddeployrunningsecretshistory scansdependenciesscheduled rescansconfigurationadmissionimageregistry rescans
Each scan at its earliest useful point, and again later. Dots are checks at a moment in time. Dashed lines are repeated scans, because new vulnerabilities are discovered in code that has not changed.

Secret scanning:

  1. Pre-commit hook on the developer's machine, so a key never enters history.
  2. Push protection on the platform, which rejects a push containing a known kind of secret.
  3. Every pull request, because hooks can be skipped.
  4. Occasional full-history scans, to find old secrets committed before scanning existed.

Dependency scanning:

  1. Every pull request, mainly to flag newly added or upgraded libraries.
  2. Scheduled scans of main, such as daily, because a library that was clean yesterday may have a new CVE today.
  3. Update bots opening fix pull requests automatically (question 166).

Infrastructure and Kubernetes configuration:

  1. Every pull request that changes Terraform files, Helm charts or manifests, with tools such as Checkov, Trivy's configuration scanner, or Kyverno's command-line check.
  2. Admission in the cluster, because changes can arrive by other routes (question 500).

Image scanning:

  1. Right after the build, before pushing or promoting.
  2. Continuously in the registry.
  3. At deployment, as a gate: the cluster accepts only images with a recent passing scan.
  4. Inventory of what runs, so a new critical CVE can be mapped to running workloads in minutes (question 441).

Combine chapters into one PDF

Pick the chapters you want. They print in the order you pick them.

Interview Prep
Docker, CI/CD, Kubernetes & Cloud
Your project
Docker
CI/CD
Kubernetes
Cloud
Observability
Scenarios
Other topics
Nothing picked yet