Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Limiting Jenkins pipeline to running only on specific nodes

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?

like image 717
Opher Lubzens Avatar asked Mar 07 '17 15:03

Opher Lubzens


People also ask

How can you prevent from several pipeline jobs of the same type to run in parallel on the same node?

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.

Can a single Jenkin job run on multiple nodes?

You can now launch all a job on all nodes.


1 Answers

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.

like image 169
Jon S Avatar answered Sep 20 '22 03:09

Jon S