Details
-
New Feature
-
Status: Closed (View Workflow)
-
Minor
-
Resolution: Duplicate
-
None
-
-
Declarative - 1.2
Description
It would be useful to be able to lock multiple stages as a single lock. For example, we usually have a stage to deploy to an environment and then another stage to run end-to-end tests on that environment, but there should be no other concurrent deployments until both stages have completed.
Something like this:
pipeline { stages { lock(resource: 'myResource', inversePrecedence: true) { stage('Deploy') { // deploy to environment } stage('E2E') { // run tests on the environment milestone 1 } } } }
Technically both stages could just be merged into a single stage but to me that defeats the purpose of stages.
Attachments
Issue Links
- duplicates
-
JENKINS-48380 Block-scoped "wrapper" options for individual stages
-
- Closed
-
-
JENKINS-46809 Allow sequential stages inside parallel in Declarative syntax
-
- Closed
-
- is duplicated by
-
JENKINS-45138 How do I `lock` outside of a step in a declarative pipeline job?
-
- Resolved
-
- relates to
-
JENKINS-45138 How do I `lock` outside of a step in a declarative pipeline job?
-
- Resolved
-
- links to
abayer, I'm trying to lock multiple stages based on the Jenkins node on which the stages will execute. It seems like the only way to do this is using the `options` block that you specified:
Unfortunately, the resource this attempts to lock is `null`:
It appears that this won't work because the stage's `options` directive occurs before entering the agent. The declarative pipeline syntax documentation says:
Is there any way to lock multiple stages for a single env.NODE_NAME? Ideally, other subsequent stages could still run in parallel with other builds (i.e. so limiting executors to 1 or disabling concurrent builds are not options).