Distributing a Jenkins Build

30 minutes
  • 3 Learning Objectives

About this Hands-on Lab

In this hands-on lab we will be creating a build agent on a second server, and then creating a build that runs only on that server. This will demonstrate the use of labels for the build.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Configure SSH on the Remote Agent

Log into the master via SSH. From the master node, use SSH to log into the worker node.

On the worker node, create the directory for the user’s home:

sudo mkdir /var/lib/jenkins

Add the user, assigning the home directory:

sudo useradd -d /var/lib/jenkins jenkins

Make the user the owner of their home directory:

sudo chown -R jenkins:jenkins /var/lib/jenkins

Create an .ssh directory for the jenkins user:

sudo mkdir /var/lib/jenkins/.ssh

Run ssh-keygen. Hit Enter to accept defaults until it completes.

Copy the contents of ~/.ssh/id_rsa.pub to the file /var/lib/jenkins/.ssh/authorized_keys

cat ~/.ssh/id_rsa.pub # Copy the output

sudo vi /var/lib/jenkins/.ssh/authorized_keys # Paste the output of cat and save

Copy the contents of id_rsa, as this is the private key that we will paste into Jenkins.

Exit the worker node.

Create an .ssh directory on the master in the jenkins directory:

sudo mkdir /var/lib/jenkins/.ssh

Copy the known_hosts entry over from the /home/cloud_user/.ssh directory to the jenkins user’s .ssh:

cp ~/.ssh/known_hosts /var/lib/jenkins/.ssh
Set up the Node on the Jenkins Master

Log into the Jenkins master web interface at port :8080 using these credentials: username: student password: OmgPassword!.

In the Jenkins master, go to Manage Jenkins and select Manage Nodes and Clouds.

On this page, add a node.

Name the node worker1.

On the Remote root directory line, type /var/lib/jenkins.

Set the number of executors to 2.

On the Host line enter the IP address of the worker

On the Credentials line click Add.

In the credentials configuration page, set the type to SSH Username with private key.

Enter the username jenkins.

Enter the contents of the id_rsa as the key.

Set the description to jssh.

Save.

Select the credential you just created as the SSH credential.

Save.

Go to the worker node logs and ensure that the worker node is set up correctly.

Test a Remote Build

Configure the master to use labels, to ensure default builds run on the remote:

  • On the master node, on the left go to Manage Jenkins.
  • Select Configure System.
  • On the Labels line, enter master.
  • Set Usage to Only build jobs with label expressions matching this node.
  • Save.

Create a Freestyle project.

Create a build step that runs a shell command.

Enter:

hostname > location.txt

Create a post build step that archives the *.txt files.

Run the build.

Check the log to ensure that the build ran on the remote agent.

Check the artifact to ensure that it contains the hostname of the remote worker.

Additional Resources

Your company has decided that they need to scale out their Jenkins installation, and that running projects on the master is no longer desirable. You have been tasked with configuring a build agent on a second server. Log into the Jenkins master web interface at port :8080 using these credentials: username: student password: OmgPassword!.

It should have the following configuration:

  • The node name should be worker1.
  • It should connect via SSH with keys.
  • The root directory should be /var/lib/jenkins.
  • The remote user should be jenkins.
  • The remote should have 2 executors.
  • All builds should be configured to run on the agent by default.
  • Ensure that the build is running on the agent by issuing a hostname command.
  • Verify that the agent builds are able to be archived and fingerprinted.
What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Get Started
Who’s going to be learning?

How many seats do you need?

  • $499 USD per seat per year
  • Billed Annually
  • Renews in 12 months

Ready to accelerate learning?

For over 25 licenses, a member of our sales team will walk you through a custom tailored solution for your business.


$2,495.00

Checkout
Sign In
Welcome Back!
Thanks for reaching out!

You’ll hear from us shortly. In the meantime, why not check out what our customers have to say about ACG?