Part 1: Install Jenkins on Ubuntu
Step 1: Update System Packages
sudo apt update && sudo apt upgrade -y
Step 2: Install Java
Jenkins requires Java to run. Install OpenJDK:
sudo apt install -y openjdk-11-jdk
Verify Java installation:
java -version
Step 3: Add Jenkins Repository
Add the Jenkins key and repository:
curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee \
/usr/share/keyrings/jenkins-keyring.asc > /dev/null
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list > /dev/null
Update the package list:
sudo apt update
Step 4: Install Jenkins
sudo apt install -y jenkins
Start and enable Jenkins:
sudo systemctl start jenkins
sudo systemctl enable jenkins
Step 5: Access Jenkins Web Interface
-
Open your browser and go to:
http://<server-ip>:8080
-
Retrieve the initial admin password:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
-
Use this password to log in and complete the setup wizard by installing recommended plugins.
Part 2: Setup Jenkins Master-Slave Configuration
Step 1: Add a Slave Node
-
Log in to the Jenkins dashboard.
-
Navigate to
Manage Jenkins
→Manage Nodes and Clouds
. -
Click New Node.
-
Enter a name for the node (e.g.,
slave-node-1
) and select Permanent Agent. -
Configure the node:
-
Remote root directory: Directory on the slave where Jenkins files will be stored (e.g.,
/home/jenkins
). -
Labels: Add labels to identify this node for specific jobs.
-
Save the configuration.
-
Step 2: Prepare the Slave Node
-
Install Java on the slave machine:
sudo apt update && sudo apt install -y openjdk-11-jdk java -version
-
Create a directory for Jenkins:
mkdir /home/jenkins
Step 3: Configure SSH Access
-
Generate SSH keys on the master server:
ssh-keygen -t rsa -b 4096
-
Copy the public key to the slave machine:
ssh-copy-id user@slave-ip
-
Test SSH access:
ssh user@slave-ip
Step 4: Connect the Slave Node
-
On the Jenkins master dashboard, edit the node configuration:
-
Select Launch agents via SSH.
-
Enter the slave's IP address, credentials (username/password or private key).
-
Test the connection to ensure successful setup.
-
-
Save the configuration.
Step 5: Verify Node Connection
-
Go to
Manage Jenkins
→Manage Nodes and Clouds
. -
Check the status of the slave node. It should show as online.
Step 6: Assign Jobs to the Slave Node
-
Open a Jenkins job configuration.
-
Scroll to the "Restrict where this project can be run" section.
-
Enter the label of the slave node.
-
Save the configuration.
Troubleshooting
-
SSH Errors: Ensure the slave node allows SSH connections and that the user has the correct permissions.
-
Agent Not Starting: Check logs on the slave node or
/var/log/jenkins/jenkins.log
on the master. -
Firewall Rules: Ensure port
22
(SSH) and8080
(Jenkins) are open on the respective machines.