Configuring Build Agents in Jenkins

45 minutes
  • 3 Learning Objectives

About this Hands-on Lab

In this hands-on lab, we will create build agent accounts on our remote agents that will then be used to connect those to the Jenkins server to allow us to build remote jobs in a more secure way. We will use specific accounts for the build agents that are not used by normal users and are accessed by the Jenkins server via SSH keys. This can be done as part of a more secure strategy for deploying build agents, and it also allows for better Audit Trail management.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Log In to the Jenkins Master, and Set Up Keys for the `cloud_user` on the Agent Server
  1. Log in to the Jenkins server via SSH using the cloud_user credentials provided.
  2. From the Jenkins server, access the agent as the jagent user via SSH.
  3. Ensure jagent‘s home directory is in /var/lib, and then exit the agent machine.
  4. On the Jenkins server as cloud_user, generate SSH keys using all defaults (no passphrase).
  5. Copy the keys from cloud_user on the Jenkins server to jagent on the agent server.
  6. Verify you are able to log in to the agent server as jagent without a password.
Copy the `.ssh` Information from `cloud_user` to the `jenkins` User
  1. Log in to the Jenkins server via SSH using the cloud_user credentials provided.
  2. Verify there is not an .ssh directory in the jenkins user’s home directory.
  3. Using sudo, copy the contents of the .ssh directory from /home/cloud_user/.ssh to /var/lib/jenkins/.ssh.
  4. Verify the necessary items are located in the /var/lib.jenkins/.ssh directory and the permissions are correct.
  5. Correct the permissions on the /var/lib/jenkins/.ssh directory so jenkins is the owner.
Configure the Agent in the Jenkins GUI
  1. Copy the contents of /var/lib/jenkins/.ssh/id_rsa.
  2. Log in to the Jenkins GUI using the credentials provided on the lab page.
  3. Navigate to Manage Jenkins > Manage Nodes and Clouds > New Node.
  4. The agent should be named Ubuntu_Agent, and select Permanent Agent.
  5. Configure the agent with four executors, and set the IP address as the hostname.
  6. Add the credentials as SSH with private key.
  7. Complete the configuration using the parameters provided.
  8. Verify the agent comes online.

Additional Resources

In order to maintain a certain level of compliance, it has become necessary to change the way build agents are being deployed. You have been given a Jenkins server you will need to connect to a new build agent.

The Jenkins GUI login is:

  • User: student
  • Password: OmgPassword!

You will need to ensure the build agent has an account that only it uses. This user account is named jagent with a password Zaq1Xsw2 and has the home directory /var/lib/jagent.

You will need to create SSH keys on the Jenkins server, and ensure they are being used to access the target agent account. This build agent should use SSH via keys with host key verification. The agent should be named Ubuntu_agent, and it should be set to use labels. It should be labeled Ubuntu_agent and have four executors.

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.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?