Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

locking nodes in stage locks #729

Open
AFriemann opened this issue Nov 14, 2024 · 3 comments
Open

locking nodes in stage locks #729

AFriemann opened this issue Nov 14, 2024 · 3 comments

Comments

@AFriemann
Copy link

AFriemann commented Nov 14, 2024

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

@mPokornyETM
Copy link
Contributor

mPokornyETM commented Nov 22, 2024

#729

sorry I must stopped lauthing, then I will try to find some for solution.
:-)

@mPokornyETM
Copy link
Contributor

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().

@AFriemann
Copy link
Author

@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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants