Your pipeline should automatically roll back the Kubernetes deployment if the post-deploy smoke test fails. Design it.
IntermediateScenarioPipeline design & Jenkinsfile decisions
Answer
Situation read → Deploy, verify, and undo on failure within the same stage.
What I'd do →
stage('Deploy prod') {
steps {
container('kubectl') {
sh 'kubectl -n shack-prod set image deploy/shack-app app=$IMAGE:$TAG'
sh 'kubectl -n shack-prod rollout status deploy/shack-app --timeout=180s'
sh './ci/smoke.sh https://shack.example.com'
}
}
post {
failure { container('kubectl') { sh 'kubectl -n shack-prod rollout undo deploy/shack-app' } }
}
}
- Annotate the change cause (
kubernetes.io/change-cause) with the build URL. - Alert the channel on rollback.
Why → rollout status catches failed pods, the smoke test catches broken behaviour, and post failure handles both.
Interview tip → Mention progressive delivery (Argo Rollouts) as the next step beyond scripted rollback.
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?BeginnerDevelopers want to rerun only the deploy stage when it fails due to a flaky cluster API, without rebuilding the image. What do you offer?IntermediateA 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.Intermediate