Developers want to rerun only the deploy stage when it fails due to a flaky cluster API, without rebuilding the image. What do you offer?
IntermediateScenarioPipeline design & Jenkinsfile decisions
Answer
Situation read → Rebuilding is slow and produces a different artifact; we want to retry with the same image.
What I'd do →
- Ensure the deploy stage is a top-level declarative stage so Restart from Stage is available.
- Pass the image tag through
envcomputed from the commit (deterministic), not from a stash. - Add automatic retry only for infrastructure errors around the API calls:
retry(count: 2, conditions: [kubernetesAgent(), nonresumable()]), plus aretry(2)aroundkubectl applywith backoff. - Enable
preserveStashes(buildCount: 5)if the stage needs stashed manifests.
Why → Restart from Stage reuses earlier stage results and redeploys the exact same artifact.
Interview tip → Connect to "build once, deploy many".
More on Pipeline design & Jenkinsfile decisions
A team's PR builds pile up: every push to an open PR starts a new 25-minute build while the old one keeps running. What do you change?BeginnerA deploy pipeline waits on `input` for approval, and on Monday you find 14 pods sitting idle since Friday. Fix it.IntermediateUnit tests, lint, dependency audit and SAST run sequentially and take 22 minutes. How do you restructure the pipeline?BeginnerA pipeline must run integration tests against a shared staging database that can only handle one test run at a time across four different repos. How do you coordinate?IntermediateA library must be tested on Node 18, 20 and 22, on Linux and Windows, but Node 18 on Windows is not supported. Design the stage.IntermediateYour 700-line Jenkinsfile now fails with `Method code too large!`. You need a fix today and a plan for next month.Advanced