A stage should run only when files under `infra/` changed, but on new branches it never runs. Why, and what do you do?
AdvancedScenarioPipeline design & Jenkinsfile decisions
Answer
Situation read → when { changeset 'infra/**' } compares against changes since the previous build of that branch job. The first build of a new branch has no recorded changesets, so the condition is false.
What I'd do →
- Compute the diff against the target branch yourself:
when { expression { sh(script: 'git diff --name-only origin/main...HEAD | grep -q "^infra/"', returnStatus: true) == 0 } } - Ensure the clone fetches
main(not a shallow single-branch clone). - For PRs, use
CHANGE_TARGETinstead of hardcodingmain.
Why → Diffing against the merge base is deterministic regardless of build history.
Interview tip → Knowing the first-build changeset gotcha signals real Jenkins experience.
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