Two commits land seconds apart and two deploys to the same environment run concurrently, corrupting state. What do you change?
IntermediateScenarioJenkins Pipelines and Agents
Answer
Situation read → Missing mutual exclusion on a shared environment.
What I'd do →
- Use
options { disableConcurrentBuilds(abortPrevious: true) }for the branch if only the latest matters. - For environment-level locking across jobs use the Lockable Resources plugin:
lock(resource: 'prod-deploy') { ... }. - Add
milestone()steps so older builds are skipped once a newer one passes that point.
Why → Deploys to one environment must be serialized, and stale builds should not overwrite newer ones.
Interview tip → Mention milestone - many candidates only know disableConcurrentBuilds.
More on Jenkins Pipelines and Agents
Your team still builds jobs by clicking through Freestyle jobs in the Jenkins UI. A new service is starting. What do you set up instead?BeginnerA Jenkins build takes 40 minutes because unit tests, linting and security scans run one after another. How do you speed it up?BeginnerBuilds queue for 20 minutes during the morning rush, but the Jenkins nodes are mostly idle at night. What do you do?IntermediateA build works on agent A but fails on agent B with "command not found: mvn". How do you stop this class of problem?BeginnerYou need a pipeline to build a branch automatically on push without polling. How do you wire it?BeginnerOnly the main branch should deploy; feature branches and PRs should only build and test. How do you express this?Beginner