Interview questions and model answers
"Write a pipeline for build, test, staging deploy, approval and production deploy."
I'd use declarative with agent none and per-stage Kubernetes pod agents. Parallel unit tests and static analysis with failFast; build the image once with Kaniko tagged by commit SHA and push to ECR using IRSA; scan it with Trivy and fail on criticals; promote to staging by updating the GitOps overlay so Flux deploys; run smoke tests; an approval stage using the input directive with agent none, a timeout and a restricted submitter group; then promote the same tag to the prod overlay and verify SLOs. Options for timeout, build retention and disableConcurrentBuilds; lock around promotions; notifications in post on failure and fixed; cleanWs in cleanup.
"Declarative or scripted?"
Declarative for application pipelines: validated before running, consistent, readable, with built-in post, when, matrix and stage restart. Scripted, or script {} blocks, only for logic declarative can't express — and that logic usually belongs in a tested shared library step.
"How do you pass a value computed in one stage to a later stage?"
Set env.NAME inside a script block — it persists for the run. If the later stage runs on a different agent and needs files, stash them or publish to a repository. Local def variables only live inside their script block.
"Why put input outside an agent?"
Because while waiting for a human, an agent-scoped input holds an executor — or with Kubernetes agents, a running pod — possibly for hours. Using agent none with the stage-level input directive releases resources until approval, then allocates an agent for the actual work.
"How do you stop two builds deploying to staging at the same time?"
disableConcurrentBuilds() for the job, and a lock on the environment resource for deploy stages that different jobs share. milestone ensures an older build can't deploy after a newer one has passed the same point.
"A security scan finds critical CVEs. How does the pipeline prevent a deploy?"
The scan stage runs Trivy with --exit-code 1 for critical (and optionally high) findings, which fails the stage; since deploy stages come after it, they never run. I'd allow a documented exception mechanism (a .trivyignore reviewed by security, with expiry) so teams aren't blocked by unfixable or false-positive findings.
"What's the difference between failure, unstable and aborted in post?"
Failure is a failed step or error; unstable usually comes from test or quality reporting (junit with failing tests, unstable()); aborted is a manual abort or a timeout. They need different handling — notifying on failure, deciding whether unstable builds may deploy, and making sure cleanup always runs in cleanup.