Some tests are flaky and fail one build in ten. Product wants green builds now. What do you do in Jenkins, and what do you refuse to do?
IntermediateScenarioPipeline design & Jenkinsfile decisions
Answer
Situation read → Retrying the whole stage hides real failures; we need targeted mitigation and tracking.
What I'd do →
- Retry at the test-framework level for known flaky tests only (
jest --retryTimesscoped by tag, Maven SurefirererunFailingTestsCount=2); Surefire reports flakes in XML. - Track flaky tests with JUnit history and quarantine them into a separate non-blocking stage using
catchError(buildResult: 'SUCCESS', stageResult: 'UNSTABLE'). - Use
retrywithconditions: [agent(), kubernetesAgent()]only for infra failures. - Refuse a blanket
retry(3)around the test stage.
Why → Blind retries turn real intermittent bugs into invisible production incidents.
Interview tip → Separate infra flakiness (retry) from test flakiness (fix or quarantine).
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