1. Overview

In this tutorial, we’ll go over the concept of distributed builds in Jenkins Architecture. Furthermore, we’ll learn how we can configure Jenkins master-slave architecture. Additionally, we’ll build a pipeline on Jenkins master to run build jobs on the slave nodes.

2. Distributed Builds

Ideally, the machine where we install standard Jenkins will be our Jenkins master. On the slave node machine, we will install a runtime program called Agent. Installing Agent will not be a standard Jenkins install, but this Agent will run on the JVM. It is capable enough to run the subtask or main task of Jenkins in a dedicated executor:

Distributed Build

We can have any number of Agent nodes or slave nodes. Further, we can configure the master node to decide which task or job should run on which agent and how many executor agents we can have. The communication between master and Jenkins slave nodes is bi-directional and takes place over TCP/IP.

3. Configuring Jenkins Master and Slave Nodes

The standard Jenkins installation includes Jenkins master, and in this setup, the master will be managing all our build system’s tasks. If we’re working on a number of projects, we can run numerous jobs on each one. Some projects require the use of specific nodes, which necessitates the use of slave nodes.

The Jenkins master is in charge of scheduling jobs, assigning slave nodes, and sending builds to slave nodes for execution. It will also keep track of the slave node state (offline or online), retrieve build results from slave nodes, and display them on the terminal output. In most installations, multiple slave nodes will be assigned to the task of building jobs.

Before we get started, let’s double-check that we have all of the prerequisites in place for adding a slave node:

    • Jenkins Server is up and running and ready to use
    • Another server for a slave node configuration
    • The Jenkins server and the slave server are both connected to the same network

To configure the Master server, we’ll log in to the Jenkins server and follow the steps below.

First, we’ll go to “Manage Jenkins -> Manage Nodes -> New Node” to create a new node:

Manage nodes

On the next screen, we enter the “Node Name” (slaveNode1), select “Permanent Agent”, then click “OK”:

new node

After clicking “OK”, we’ll be taken to a screen with a new form where we need to fill out the slave node’s information. We’re considering the slave node to be running on Linux operating systems, hence the launch method is set to “Launch agents via ssh”.

In the same way, we’ll add relevant details, such as the name, description, and a number of executors.

We’ll save our work by pressing the “Save” button. The “Labels” with the name “slaveNode1” will help us to set up jobs on this slave node:

new node2

4. Building the Project on Slave Nodes

Now that our master and slave nodes are ready, we’ll discuss the steps for building the project on the slave node.

For this, we start by clicking “New Item” in the top left corner of the dashboard.

Next, we need to enter the name of our project in the “Enter an item name” field and select the “Pipeline project”, and then click the “OK” button.

On the next screen, we’ll enter a “Description” (optional) and navigate to the “Pipeline” section. Make sure the “Definition” field has the Pipeline script option selected.

After this, we copy and paste the following declarative Pipeline script into a “script” field:

    stage('Build') {
        sh '''echo build steps'''
    stage('Test') {
        sh '''echo test steps'''

Next, we click on the “Save” button. This will redirect to the Pipeline view page.

On the left pane, we click the “Build Now” button to execute our Pipeline. After Pipeline execution is completed, we’ll see the Pipeline view:

ms pipeline console output

We can verify the history of the executed build under the Build History by clicking the build number. As shown above, when we click on the build number and select “Console Output”, we can see that the pipeline ran on our slaveNode1 machine.

5. Conclusion

In this tutorial, we’ve covered what a Distributed Build is in Jenkins, and we saw how the Jenkins master node invokes the slave nodes. Additionally, we learned how to set up a Jenkins master-slave configuration. Finally, we’ve put the slave node configuration to the test.

Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.