0

I need to run commands on my pipeline during a certain stage, on devices which connected to my Jenkins as slaves. But I want them to run only when another one finished. On the other hand, I want them to run all previous stages before they "wait" for another device to finish.

What is the best way to implement this lock? Again, it is the same job, but different slaves.

0

There is no perfect way to do this that I know of. To explain why, take this pipeline script as an example:

node('my-first-node') {
  stage('my-first-stage') {
    // some steps here 
  }
}

node('my-second-node') {
  stage('my-second-stage') {
    // some steps here
  }
}

node('my-first-node') {
  stage('my-third-stage') { // must be run after my-second-stage
    // some steps here
  }
}

This will run your stages in the correct order, but there is no guarantee that the node assigned to run my-first-stage will be the same node as the one assigned to run my-third-stage. Furthermore, even if you can be confident that they are the same node (for instance, you only have one node with the "my-first-node" label in your executor pool), there is no guarantee that the assigned workspace folder will be the same for both stages either. And even if you use the workspace step to manually assign a workspace directory, there is no guarantee that the assigned workspace directory will be the one you asked for either.

However, if you don't care that my-first-stage and my-third-stage run in the same workspace directory on the same node and you only care about the order that your steps run in, this works fine.

0

I found exactly what I was looking for-

[Jenkins plugin] (https://wiki.jenkins.io/display/JENKINS/Lockable+Resources+Plugin)

Which let you create a lock between, slaves , different jobs and more..

(in contrast to the plugin description)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.