If you have lots of jobs in your Jenkins installation, you might want to distribute the work it takes to build them.
Jenkins nodes can be arranged in a master/slave fashion, where the master can delegate some builds to the slave nodes, allowing you to scale in the number of jobs configured in a given installation. A slave node is a computer used solely to build jobs. This is required for the node to run the slave agent.
Use the cloud
Delivery of software products is spiky by nature. Commits and build activities peak during the release phase of the product. Thus, more slaves can be kicked off during peak usage. Teams can also use the Amazon EC2 plugin to offload their builds into the Amazon IaaS. With this setup, teams are responsible for management of masters and slaves in the cloud.
A more advanced option is to use CloudBees DEV@cloud service and let CloudBees manage Jenkins masters and slaves. With the service, teams can just focus on development and do not need to worry about infrastructure.
Creating a Node
Click on the Manage Nodes option of the configuration page. You will notice the New Node option on the left sidebar. Click on it to create a new node, and enter the information for the new node, mainly the name.
Next, configure the node settings:
- # of Executors: How many jobs can be built on this node at the same time.
- Remove FS root: Where the Jenkins files will be stored in the remote node, analogous to JENKINS_HOME.
- Labels: Custom labels that you want to assign to this node and others, to create groups of nodes suitable to build some specific jobs.
- Usage: You can set this node to build any jobs or only the ones specifically tied to it.
Launching the Slave agent via SSH
Jenkins has an embedded SSH client, which is very useful (in this particular case) to make it connect to the target machine, by providing the connection information and credentials, and running the slave agent automatically. Select the Launch slave agents on Unix machines via the SSH option, and then fill in the required information.
The node should then start right away as soon as you save the node configuration.
Launching the Slave agent via Java Web Start
Another option is to run the slave agent manually, via Java Web Start. Select the Launch slave agents via the Java Web Start option. Then log in to the target machine, and use this command line:
Replace ip:port with the location of the master Jenkins node, and replace nodename with the name of the node you've created (in this case, for example, it would be "My new Node" with spaces and without the quotes).
Launching the Slave agent headlessly
You can also run the slave agent without a GUI, suitable to make it automatically run at system startup, by downloading: http://ip:port/jnlpJars/slave.jar
and then running:
java -jar slave.jar -jnlpUrl
Configuring environment variables
You can set any environment variables needed in the slave node by setting the node properties, these will help you customize the build and maybe dynamically generate files or reports.
Configuring the slave node Java tools
If the path for Maven, Ant, and the JDK is different from the ones in the master node, you can set these in the Tool Locations section. Once the node is configured and connected, you should see the new node Queue Status right below the main build queue.
Restricting where jobs are built
You can set (restrict) where a job can be built right in your job configuration by choosing the "Restrict where this project can be run". A label expression that allows boolean operators can be set, describing which nodes can handle this job. To see the complete list of available boolean operators, click the help icon at the right.