jenkinsci / jenkinsci/lockable-resources-plugin
locking nodes in stage locks
- Dominant language
- Java
- Stars
- 99
- Forks
- 205
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 8
Description
### What feature do you want to see added?
Heya,
similar to #685 I've been trying to lock some stages based on dynamic values (the env.NODE_NAME)
unfortunately Jenkins seems to evaluate the parameters before the node exists, so the lock creation fails
```groovy
pipeline {
agent any
stages {
stage('top stage') {
options {
lock(env.NODE_NAME)
}
stages {
stage('test') {
steps {
echo "test"
sh 'sleep 30'
}
}
stage('cleanup') {
steps {
echo "cleanup"
}
}
}
}
}
}
```
The annoying part is that the `lock` seems to be executed when the stage starts, so after node provisioning, but it seems impossible to inject a variable at that time that's not known during build start.
For additional context: our nodes are created dynamically so it's not possible to know the name ahead of time and if I ask our devs to start adding scripted pipelines on top of their declarative ones I'm afraid they'll throw their keyboards at me, so that doesn't seem like a good solution either.
Is there a known workaround, or would it be possible to add an argument to use the current node as resource name?
Thanks!
### Upstream changes
_No response_
### Are you interested in contributing this feature?
I'd be happy to but I wouldn't even know where to start
Contributor guide
Research direction
The issue names no source files or tests; begin by reproducing the Declarative Pipeline example using lock(env.NODE_NAME) with dynamically provisioned nodes. Trace when the stage option and lock resource are evaluated, then define completion as a supported way to lock the current node without requiring a pre-known resource name or a scripted pipeline.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy, java
- Domain
- ci-cd, devops
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100