Jenkins And Build Agents

Overview

In this article, I’ll provide instructions in how I installed Jenkins and the two Jenkins Build Agents in my environment.

System Requirements

I used one of my standard templates in vCenter to create the three Jenkins nodes. All three servers have 2 CPUs and 4 Gigs of Memory. For the main Jenkins server, 64 Gigs of storage is sufficient. For Build Agents, 200 Gigs of Storage is recommended. Basically as much as you need when storing deployment jobs. My photos website has about 30 Gigs of pictures. With deployments going to 3 sites (local for testing, docker for the future, and the remote public visible site), that means just the photos website takes almost 100 gigs. Jenkins will require Java 1.8 to be installed prior to installing Jenkins.

Firewall Configuration

As part of Zero Trust Networking, each system has a firewall. You’ll need to configure the firewall for the Jenkins nodes.

firewall-cmd --permanent --new-service=jenkins
firewall-cmd --permanant --service=jenkins --set-short="Jenkins ports"
firewall-cmd --permanent --service=jenkins --set-description="Jenkins port exceptions"
firewall-cmd --permanent --service=jenkins --add-port=8080/tcp
firewall-cmd --permanent --add-service=jenkins
firewall-cmd --zone=public --add-service=http --permanent
firewall-cmd --reload

Installing Jenkins

You’ll need to install the repository configuration and GPG keys, then install Java and finally Jenkins.

wget -O /etc/yum.repos.d/jenkins.repo \
    https://pkg.jenkins.io/redhat-stable/jenkins.repo
rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
yum upgrade
yum install java-8-openjdk
yum install jenkins
systemctl daemon-reload

Enable and Start Jenkins

Pretty simple process here. You enable and start Jenkins.

systemctl enable jenkins
systemctl start jenkins

Configure Users

During the installation process, a password was created so you can Unlock the Jenkins installation. Copy it from
/var/lib/jenkins/secrets/initialAdminPassword and paste it into the Unlock screen. Once Jenkins is unlocked, you’ll be presented with a Create Administrator page. Fill it in and save it. Once done, you can then access Jenkins and install any plugins you want to use.

Build Agents

In order to effectively use Jenkins, the main node that you installed shouldn’t be processing any jobs. If it processes jobs, it can be overwhelmed and other jobs might queue up delaying deployments. For my homelab it’s not so critical however I am trying to emulate a production like environment so having Build Agents will satisfy that requirement.

Configuring the Build Agents

Jenkins requires a few things before the main system can incorporate a Build Agent. You’ll need to create the jenkins account.

useradd -d /var/lib/jenkins -c "Jenkins Remote Agent" -m jenkins

Of course set a password. Something long and hard to figure out. Then create your public/private key pair. This is used to communicate with the necessary servers.

ssh-keygen -t rsa

This creates the key pair in the Jenkins .ssh directory.

Next is install Java 1.8. Jenkins will communicate with Java in order to run jobs.

yum install -y java-1.8.0-openjdk-headless
Installed:
  java-1.8.0-openjdk-headless.x86_64 1:1.8.0.272.b10-1.el7_9

Dependency Installed:
  copy-jdk-configs.noarch 0:3.3-10.el7_5             javapackages-tools.noarch 0:3.4.1-11.el7              lksctp-tools.x86_64 0:1.0.17-2.el7
  pcsc-lite-libs.x86_64 0:1.8.8-8.el7                python-javapackages.noarch 0:3.4.1-11.el7             python-lxml.x86_64 0:3.2.1-4.el7
  tzdata-java.noarch 0:2020d-2.el7

Complete!

Now that the node is prepared, in Jenkins you’ll need to add a node. Click Manage Jenkins and Manage Nodes and Clouds. Then click on New Node. Once you name it, you’ll fill out the form as follows:

  • Name: Remote Build 2 (this is my first Jenkins Build Agent)
  • Description: Access to the remote server for local files
  • Number of Executors: 2 (rule of thumb is 1 per CPU)
  • Remote root directory: /var/lib/jenkins (the jenkins account home dir)
  • Labels: guardian (the label you’ll use in jobs to determine which Build Agent to use)
  • Usage: Select Only build jobs with label expressions matching this node
  • Launch method: Select Launch agents via SSH
  • Host: 192.168.104.82 (I tend to avoid using DNS as it can be unreliable)
  • Credentials: Select Remote schelin.org server
  • Host Key Verification Strategy: Select Known hosts file Verification Strategy
  • Availability: Select Keep this agent online as much as possible

When you’re done, click Save and the node will show up in the list of nodes. Then create the second Build Agent following the above installation instructions and configure it as follows.

  • Name: Local Build 3 (this is my second Jenkins Build Agent)
  • Description: Local Server Builds
  • Number of Executors: 2 (rule of thumb is 1 per CPU)
  • Remote root directory: /var/lib/jenkins (the jenkins account home dir)
  • Labels: local (the label you’ll use in jobs to determine which Build Agent to use)
  • Usage: Select Only build jobs with label expressions matching this node
  • Launch method: Select Launch agents via SSH
  • Host: 192.168.104.81 (I tend to avoid using DNS as it can be unreliable)
  • Credentials: Select Local environment
  • Host Key Verification Strategy: Select Known hosts file Verification Strategy
  • Availability: Select Keep this agent online as much as possible

And when done, click Save and the node will show up

References

This entry was posted in Computers, Jenkins and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *