Interview Prep/Jenkins/Declarative pipeline syntax

What does `lock` do and which plugin provides it?

IntermediateConceptDeclarative pipeline syntax
Answer

The Lockable Resources plugin provides lock, which serialises access to a named resource across all jobs: a shared test environment, a database, a device.

stage('Integration') {
  options { lock(resource: 'staging-db') }
  steps { sh './run-integration.sh' }
}

lock(label: 'test-env', quantity: 1, variable: 'ENV_NAME') picks one free resource from a pool and exposes its name. disableConcurrentBuilds only limits one job; lock works across jobs.

All Jenkins questions Roadmap: Jenkins

More on Declarative pipeline syntax