Interview Prep/Jenkins/Pipeline design & Jenkinsfile decisions

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' } }
  }
}
  1. Annotate the change cause (kubernetes.io/change-cause) with the build URL.
  2. 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.

All Jenkins questions Roadmap: Jenkins

More on Pipeline design & Jenkinsfile decisions