A 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?
IntermediateScenarioPipeline design & Jenkinsfile decisions
Answer
Situation read → disableConcurrentBuilds only works per job; we need a cross-job mutex.
What I'd do →
- Install Lockable Resources and define a resource
staging-db(via JCasC underunclassified.lockableResourcesManager). - Wrap only the integration stage:
stage('Integration') { options { lock(resource: 'staging-db') } steps { sh './run-it.sh' } } - Put a
timeouton the stage so a hung test releases the lock. - Long term, give each run an ephemeral database (a Testcontainers Postgres in the pod) and remove the lock.
Why → lock queues builds across jobs and releases automatically when the block exits, even on failure.
Interview tip → Say that locks hide a scalability problem; ephemeral environments are the real fix.
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 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.IntermediateYour 700-line Jenkinsfile now fails with `Method code too large!`. You need a fix today and a plan for next month.Advanced