Interview Prep/Jenkins/Pipeline design & Jenkinsfile decisions

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 →

  1. Install Lockable Resources and define a resource staging-db (via JCasC under unclassified.lockableResourcesManager).
  2. Wrap only the integration stage:
    stage('Integration') {
      options { lock(resource: 'staging-db') }
      steps { sh './run-it.sh' }
    }
    
  3. Put a timeout on the stage so a hung test releases the lock.
  4. 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.

All Jenkins questions Roadmap: Jenkins

More on Pipeline design & Jenkinsfile decisions