Search code examples
jenkinsjenkins-pluginsjenkins-pipeline

Jenkins pipeline job, use all nodes of a given label before locking


Got a pipeline job who can run at 4 different nodes with one label. Previously I got the problem that they randomly tried to run at the same node, so I installed the lockable recourses plugin and tried this:

node('TEST') {
    try {
        notifyBuild('STARTED')
        lock(env.NODE_NAME){

This works generally, but it seems to be random which node from the Label TEST the job chooses. For example the first two job executions can choose the same node and so the 2nd job will have to wait even if there are free nodes available. Is there a way to secure that all nodes are used before jobs have to wait?


Solution

  • Better solution is the https://github.com/jenkinsci/throttle-concurrent-builds-plugin which also works for pipeline jobs. This plugin doesn´t checks if recources are available before it blocks them. Also all recources are used before jobs have to wait.