I'm building jobs that will be using Jenkins piplines extensively. Our nodes are designated per project by their tags, but unlike regular jobs the pipeline build does not seem to have the "Restrict where this project can be run" checkbox. How can I specify on which node the pipeline will run the way I do for regular jobs?
Show activity on this post. Install Jenkins Lockable Resources Plugin. In your pipeline script wrap the part in the lock block and give this lockable resource a name. Use the name of whatever resource you are locking.
You can now launch all a job on all nodes.
You specify the desired node or tag when you do the node
step:
node('specialSlave') { // Will run on the slave with name or tag specialSlave }
See https://jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#node-allocate-node for an extended explanation of the arguments to node
.
Edit 2019: This answer (and question) was made back in 2017, back then there only was one flavor of Jenkins pipeline, scripted pipeline, since then declarative pipeline has been added. So above answer is true for scripted pipeline, for answers regarding declarative pipeline please see other answers below.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With