locking nodes in stage locks
Opened this issue · 3 comments
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
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
sorry I must stopped lauthing, then I will try to find some for solution.
:-)
Sorry, I stopped laugthung now. I am not sure how the parametrized pipes works. But maybe, it is possible to load some groovy shared libs. In that case you can implement your own step like lockNode().
@mPokornyETM I'm glad I'm at least providing entertainment 😆
Yeah we're heavily using shared libraries, but I haven't found a way to add a pipeline option
in there yet..
So the only way would be to either move pipelines to scripted, or implement our own lock class based on lockable resources and carry that lock through the pipeline (I've tried that first, but my Java is rusty and I thought I'll see if there's a better way first).