-
Bug
-
Resolution: Duplicate
-
Major
-
None
-
Jenkins ver. 2.63
Lockable Resource Plugin v2.0
In the freestyle/UI-based job configuration, it looks like a lock is scoped to the entire build, not one step.
The documentation for pipelines seems to imply that `lock` must be used within a `step`, but could you confirm?
I have a situation where I need to lock a resource while performing a step. I need to always cleanup that resource, so that my step works correctly.
step('foo') { lock('foo-resource') { bat '... acquire the resource...' bat '... use the resource...' bat '... cleanup the resource...' } }
I need to move the cleanup step to a `post / always`, so the step reports the correct exit code, but now it's outside of the lock.
step('foo') { lock('foo-resource') { bat '... acquire the resource...' bat '... use the resource...' } } post { always { bat '... cleanup the resource...' } }
I've got other jobs waiting for this resource and, based on the timing, they're trying to use the resource that this job is now cleaning up.
Well, I guess it's not valid around a `stage`.
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: WorkflowScript: 30: Unknown stage section "lock". Starting with version 0.5, steps in a stage must be in a steps block. @ line 30, column 9. stage('foo') { ^ WorkflowScript: 30: Nothing to execute within stage "foo" @ line 30, column 9. stage('foo') { ^
- duplicates
-
JENKINS-43336 Allow locking multiple stages in declarative pipeline
-
- Closed
-
- relates to
-
JENKINS-43336 Allow locking multiple stages in declarative pipeline
-
- Closed
-
[JENKINS-45138] How do I `lock` outside of a step in a declarative pipeline job?
Description |
Original:
The [documentation](https://wiki.jenkins.io/display/JENKINS/Lockable+Resources+Plugin) seems to imply that `lock` must be used within a `step`, but could you confirm? I have a situation where I need to lock a resource while performing a step. I need to always cleanup that resource, so that my step works correctly. ```groovy step('foo') \{ lock('foo-resource') \{ bat '... acquire the resource...' bat '... use the resource...' bat '... cleanup the resource...' } } ``` I need to move the cleanup step to a `post / always`, so the step reports the correct exit code, but now it's outside of the lock. ```groovy step('foo') \{ lock('foo-resource') \{ bat '... acquire the resource...' bat '... use the resource...' } } post \{ always \{ bat '... cleanup the resource...' } } ``` I've got other jobs waiting for this resource and, based on the timing, they're trying to use the resource that this job is now cleaning up. ---- In the freestyle/UI-based job configuration, it looks like a lock is scoped to the entire build, not one step.  |
New:
The [documentation](https://wiki.jenkins.io/display/JENKINS/Lockable+Resources+Plugin) seems to imply that `lock` must be used within a `step`, but could you confirm? I have a situation where I need to lock a resource while performing a step. I need to always cleanup that resource, so that my step works correctly. {code} step('foo') { lock('foo-resource') { bat '... acquire the resource...' bat '... use the resource...' bat '... cleanup the resource...' } } {code} I need to move the cleanup step to a `post / always`, so the step reports the correct exit code, but now it's outside of the lock. {code} step('foo') { lock('foo-resource') { bat '... acquire the resource...' bat '... use the resource...' } } post { always { bat '... cleanup the resource...' } } {code} I've got other jobs waiting for this resource and, based on the timing, they're trying to use the resource that this job is now cleaning up. ---- In the freestyle/UI-based job configuration, it looks like a lock is scoped to the entire build, not one step.  |
Description |
Original:
The [documentation](https://wiki.jenkins.io/display/JENKINS/Lockable+Resources+Plugin) seems to imply that `lock` must be used within a `step`, but could you confirm? I have a situation where I need to lock a resource while performing a step. I need to always cleanup that resource, so that my step works correctly. {code} step('foo') { lock('foo-resource') { bat '... acquire the resource...' bat '... use the resource...' bat '... cleanup the resource...' } } {code} I need to move the cleanup step to a `post / always`, so the step reports the correct exit code, but now it's outside of the lock. {code} step('foo') { lock('foo-resource') { bat '... acquire the resource...' bat '... use the resource...' } } post { always { bat '... cleanup the resource...' } } {code} I've got other jobs waiting for this resource and, based on the timing, they're trying to use the resource that this job is now cleaning up. ---- In the freestyle/UI-based job configuration, it looks like a lock is scoped to the entire build, not one step.  |
New:
The [documentation|https://wiki.jenkins.io/display/JENKINS/Lockable+Resources+Plugin] seems to imply that `lock` must be used within a `step`, but could you confirm? I have a situation where I need to lock a resource while performing a step. I need to always cleanup that resource, so that my step works correctly. {code} step('foo') { lock('foo-resource') { bat '... acquire the resource...' bat '... use the resource...' bat '... cleanup the resource...' } } {code} I need to move the cleanup step to a `post / always`, so the step reports the correct exit code, but now it's outside of the lock. {code} step('foo') { lock('foo-resource') { bat '... acquire the resource...' bat '... use the resource...' } } post { always { bat '... cleanup the resource...' } } {code} I've got other jobs waiting for this resource and, based on the timing, they're trying to use the resource that this job is now cleaning up. ---- In the freestyle/UI-based job configuration, it looks like a lock is scoped to the entire build, not one step.  |
Attachment | New: freestyle-configuration.png [ 38649 ] |
Description |
Original:
The [documentation|https://wiki.jenkins.io/display/JENKINS/Lockable+Resources+Plugin] seems to imply that `lock` must be used within a `step`, but could you confirm? I have a situation where I need to lock a resource while performing a step. I need to always cleanup that resource, so that my step works correctly. {code} step('foo') { lock('foo-resource') { bat '... acquire the resource...' bat '... use the resource...' bat '... cleanup the resource...' } } {code} I need to move the cleanup step to a `post / always`, so the step reports the correct exit code, but now it's outside of the lock. {code} step('foo') { lock('foo-resource') { bat '... acquire the resource...' bat '... use the resource...' } } post { always { bat '... cleanup the resource...' } } {code} I've got other jobs waiting for this resource and, based on the timing, they're trying to use the resource that this job is now cleaning up. ---- In the freestyle/UI-based job configuration, it looks like a lock is scoped to the entire build, not one step.  |
New:
The [documentation|https://wiki.jenkins.io/display/JENKINS/Lockable+Resources+Plugin] seems to imply that `lock` must be used within a `step`, but could you confirm? I have a situation where I need to lock a resource while performing a step. I need to always cleanup that resource, so that my step works correctly. {code} step('foo') { lock('foo-resource') { bat '... acquire the resource...' bat '... use the resource...' bat '... cleanup the resource...' } } {code} I need to move the cleanup step to a `post / always`, so the step reports the correct exit code, but now it's outside of the lock. {code} step('foo') { lock('foo-resource') { bat '... acquire the resource...' bat '... use the resource...' } } post { always { bat '... cleanup the resource...' } } {code} I've got other jobs waiting for this resource and, based on the timing, they're trying to use the resource that this job is now cleaning up. ---- In the freestyle/UI-based job configuration, it looks like a lock is scoped to the entire build, not one step. !freestyle-configuration.png|thumbnail! |
Description |
Original:
The [documentation|https://wiki.jenkins.io/display/JENKINS/Lockable+Resources+Plugin] seems to imply that `lock` must be used within a `step`, but could you confirm? I have a situation where I need to lock a resource while performing a step. I need to always cleanup that resource, so that my step works correctly. {code} step('foo') { lock('foo-resource') { bat '... acquire the resource...' bat '... use the resource...' bat '... cleanup the resource...' } } {code} I need to move the cleanup step to a `post / always`, so the step reports the correct exit code, but now it's outside of the lock. {code} step('foo') { lock('foo-resource') { bat '... acquire the resource...' bat '... use the resource...' } } post { always { bat '... cleanup the resource...' } } {code} I've got other jobs waiting for this resource and, based on the timing, they're trying to use the resource that this job is now cleaning up. ---- In the freestyle/UI-based job configuration, it looks like a lock is scoped to the entire build, not one step. !freestyle-configuration.png|thumbnail! |
New:
The [documentation|https://wiki.jenkins.io/display/JENKINS/Lockable+Resources+Plugin] seems to imply that `lock` must be used within a `step`, but could you confirm? I have a situation where I need to lock a resource while performing a step. I need to always cleanup that resource, so that my step works correctly. {code} step('foo') { lock('foo-resource') { bat '... acquire the resource...' bat '... use the resource...' bat '... cleanup the resource...' } } {code} I need to move the cleanup step to a `post / always`, so the step reports the correct exit code, but now it's outside of the lock. {code} step('foo') { lock('foo-resource') { bat '... acquire the resource...' bat '... use the resource...' } } post { always { bat '... cleanup the resource...' } } {code} I've got other jobs waiting for this resource and, based on the timing, they're trying to use the resource that this job is now cleaning up. ---- In the freestyle/UI-based job configuration, it looks like a lock is scoped to the entire build, not one step. !freestyle-configuration.png|thumbnail! |
Summary | Original: What are valid scopes for `lock` in a declarative pipeline job? | New: How do I `lock` outside of a step in a declarative pipeline job? |
Description |
Original:
The [documentation|https://wiki.jenkins.io/display/JENKINS/Lockable+Resources+Plugin] seems to imply that `lock` must be used within a `step`, but could you confirm? I have a situation where I need to lock a resource while performing a step. I need to always cleanup that resource, so that my step works correctly. {code} step('foo') { lock('foo-resource') { bat '... acquire the resource...' bat '... use the resource...' bat '... cleanup the resource...' } } {code} I need to move the cleanup step to a `post / always`, so the step reports the correct exit code, but now it's outside of the lock. {code} step('foo') { lock('foo-resource') { bat '... acquire the resource...' bat '... use the resource...' } } post { always { bat '... cleanup the resource...' } } {code} I've got other jobs waiting for this resource and, based on the timing, they're trying to use the resource that this job is now cleaning up. ---- In the freestyle/UI-based job configuration, it looks like a lock is scoped to the entire build, not one step. !freestyle-configuration.png|thumbnail! |
New:
The [documentation|https://wiki.jenkins.io/display/JENKINS/Lockable+Resources+Plugin] seems to imply that `lock` must be used within a `step`, but could you confirm? I have a situation where I need to lock a resource while performing a step. I need to always cleanup that resource, so that my step works correctly. {code} step('foo') { lock('foo-resource') { bat '... acquire the resource...' bat '... use the resource...' bat '... cleanup the resource...' } } {code} I need to move the cleanup step to a `post / always`, so the step reports the correct exit code, but now it's outside of the lock. {code} step('foo') { lock('foo-resource') { bat '... acquire the resource...' bat '... use the resource...' } } post { always { bat '... cleanup the resource...' } } {code} I've got other jobs waiting for this resource and, based on the timing, they're trying to use the resource that this job is now cleaning up. ---- In the freestyle/UI-based job configuration, it looks like a lock is scoped to the entire build, not one step. !freestyle-configuration.png|thumbnail! ---- Well, I guess it's not valid around a `stage`. {code} org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: WorkflowScript: 30: Unknown stage section "lock". Starting with version 0.5, steps in a stage must be in a steps block. @ line 30, column 9. stage('foo') { ^ WorkflowScript: 30: Nothing to execute within stage "test-contract" @ line 30, column 9. stage('foo') { ^ {code} |
Description |
Original:
The [documentation|https://wiki.jenkins.io/display/JENKINS/Lockable+Resources+Plugin] seems to imply that `lock` must be used within a `step`, but could you confirm? I have a situation where I need to lock a resource while performing a step. I need to always cleanup that resource, so that my step works correctly. {code} step('foo') { lock('foo-resource') { bat '... acquire the resource...' bat '... use the resource...' bat '... cleanup the resource...' } } {code} I need to move the cleanup step to a `post / always`, so the step reports the correct exit code, but now it's outside of the lock. {code} step('foo') { lock('foo-resource') { bat '... acquire the resource...' bat '... use the resource...' } } post { always { bat '... cleanup the resource...' } } {code} I've got other jobs waiting for this resource and, based on the timing, they're trying to use the resource that this job is now cleaning up. ---- In the freestyle/UI-based job configuration, it looks like a lock is scoped to the entire build, not one step. !freestyle-configuration.png|thumbnail! ---- Well, I guess it's not valid around a `stage`. {code} org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: WorkflowScript: 30: Unknown stage section "lock". Starting with version 0.5, steps in a stage must be in a steps block. @ line 30, column 9. stage('foo') { ^ WorkflowScript: 30: Nothing to execute within stage "test-contract" @ line 30, column 9. stage('foo') { ^ {code} |
New:
The [documentation|https://wiki.jenkins.io/display/JENKINS/Lockable+Resources+Plugin] seems to imply that `lock` must be used within a `step`, but could you confirm? I have a situation where I need to lock a resource while performing a step. I need to always cleanup that resource, so that my step works correctly. {code} step('foo') { lock('foo-resource') { bat '... acquire the resource...' bat '... use the resource...' bat '... cleanup the resource...' } } {code} I need to move the cleanup step to a `post / always`, so the step reports the correct exit code, but now it's outside of the lock. {code} step('foo') { lock('foo-resource') { bat '... acquire the resource...' bat '... use the resource...' } } post { always { bat '... cleanup the resource...' } } {code} I've got other jobs waiting for this resource and, based on the timing, they're trying to use the resource that this job is now cleaning up. ---- In the freestyle/UI-based job configuration, it looks like a lock is scoped to the entire build, not one step. !freestyle-configuration.png|thumbnail! ---- Well, I guess it's not valid around a `stage`. {code} org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: WorkflowScript: 30: Unknown stage section "lock". Starting with version 0.5, steps in a stage must be in a steps block. @ line 30, column 9. stage('foo') { ^ WorkflowScript: 30: Nothing to execute within stage "foo" @ line 30, column 9. stage('foo') { ^ {code} |
Description |
Original:
The [documentation|https://wiki.jenkins.io/display/JENKINS/Lockable+Resources+Plugin] seems to imply that `lock` must be used within a `step`, but could you confirm? I have a situation where I need to lock a resource while performing a step. I need to always cleanup that resource, so that my step works correctly. {code} step('foo') { lock('foo-resource') { bat '... acquire the resource...' bat '... use the resource...' bat '... cleanup the resource...' } } {code} I need to move the cleanup step to a `post / always`, so the step reports the correct exit code, but now it's outside of the lock. {code} step('foo') { lock('foo-resource') { bat '... acquire the resource...' bat '... use the resource...' } } post { always { bat '... cleanup the resource...' } } {code} I've got other jobs waiting for this resource and, based on the timing, they're trying to use the resource that this job is now cleaning up. ---- In the freestyle/UI-based job configuration, it looks like a lock is scoped to the entire build, not one step. !freestyle-configuration.png|thumbnail! ---- Well, I guess it's not valid around a `stage`. {code} org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: WorkflowScript: 30: Unknown stage section "lock". Starting with version 0.5, steps in a stage must be in a steps block. @ line 30, column 9. stage('foo') { ^ WorkflowScript: 30: Nothing to execute within stage "foo" @ line 30, column 9. stage('foo') { ^ {code} |
New:
In the freestyle/UI-based job configuration, it looks like a lock is scoped to the entire build, not one step. !freestyle-configuration.png|thumbnail! The [documentation|https://wiki.jenkins.io/display/JENKINS/Lockable+Resources+Plugin] for pipelines seems to imply that `lock` must be used within a `step`, but could you confirm? I have a situation where I need to lock a resource while performing a step. I need to always cleanup that resource, so that my step works correctly. {code} step('foo') { lock('foo-resource') { bat '... acquire the resource...' bat '... use the resource...' bat '... cleanup the resource...' } } {code} I need to move the cleanup step to a `post / always`, so the step reports the correct exit code, but now it's outside of the lock. {code} step('foo') { lock('foo-resource') { bat '... acquire the resource...' bat '... use the resource...' } } post { always { bat '... cleanup the resource...' } } {code} I've got other jobs waiting for this resource and, based on the timing, they're trying to use the resource that this job is now cleaning up. ---- Well, I guess it's not valid around a `stage`. {code} org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: WorkflowScript: 30: Unknown stage section "lock". Starting with version 0.5, steps in a stage must be in a steps block. @ line 30, column 9. stage('foo') { ^ WorkflowScript: 30: Nothing to execute within stage "foo" @ line 30, column 9. stage('foo') { ^ {code} |