Jenkins
Installing Jenkins
Install Jenkins on a VM
This guide demonstrates how to install Jenkins on an Ubuntu virtual machine deployed on Microsoft Azure. Although Azure is used in this example, you can easily adapt these instructions for other environments such as Hyper-V, local VMs, or an Ubuntu server installation.
Creating the Virtual Machine
Log in to the Azure Portal and navigate to Virtual Machines. Click on Create Virtual Machine to begin.
Tip: Consider available resources (RAM, CPU) during selection to match your Jenkins workload.
Choose your resource group (e.g., "KodeKloud") and enter a name for the VM. Select the Ubuntu 20.04 OS image. For a cost-effective option, opt for a VM size with 1 vCPU and 2 GB RAM.
Continue by configuring the instance details:
Set a username and password for SSH access. For demonstration purposes, open port 22.
Security Warning
Opening port 22 for SSH access is not recommended in production environments. Ensure network security groups or firewalls are correctly configured.
For storage, choose a premium SSD, add the VM to your "KodeKloud VNet", then click Next to review and confirm your settings. Enter your password again when prompted, then create the VM.
Once the VM is created, open a terminal to connect via SSH.
Connecting to Your VM
Open your terminal and connect to the VM using its public IP address. For example:
ssh [email protected]
When you see the authenticity warning, type "yes" and then provide your password:
The authenticity of host '40.121.40.56 (40.121.40.56)' can't be established. ED25519 key fingerprint is SHA256:RMqL4bPfW3a9J5ehDcKLa7kRA5UQ. This key is not known by any other names. Are you sure you want to continue connecting (yes/no/[fingerprint])? Warning: Permanently added '40.121.40.56' (ED25519) to the list of known hosts. [email protected]'s password:
Once connected, clear the terminal and update the package lists:
sudo apt update -y
Installing Prerequisites
Jenkins requires Java to run. Update your package lists and install Java with the following command:
sudo apt update -y
Example output snippet:
Get:84 http://azure.archive.ubuntu.com/ubuntu focal/main amd64 1.14-2 [16.3 kB]
...
Fetched 304 MB in 14s (21.8 MB/s)
Installing Jenkins
With Java installed, proceed to install Jenkins by following these steps:
Add the Jenkins Repository Key:
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
You should see an "OK" response.
Append the Jenkins Repository:
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable/ jenkins.list > /etc/apt/sources.list.d/jenkins.list'
Update the Package List:
sudo apt update -y
The output confirms that the Jenkins repository is being fetched:
Hit:1 http://azure.archive.ubuntu.com/ubuntu focal InRelease ... Fetched 23.9 kB in 1s (39.5 kB/s)
Install Jenkins:
sudo apt install jenkins -y
During installation, you might see logs similar to:
Selecting previously unselected package net-tools. Preparing to unpack .../net-tools_1.60+git20180626.aebd88e-1ubuntu1_amd64.deb ... ... Setting up jenkins (2.319.1) ...
Starting and Verifying Jenkins
Start the Jenkins Service:
sudo systemctl start jenkins
Verify the Service Status:
sudo systemctl status jenkins
Expected output indicates that the Jenkins service is active:
jenkins.service - LSB: Start Jenkins at boot time Loaded: loaded (/etc/init.d/jenkins; generated) Active: active (exited) since Wed 2021-12-29 16:19:03 UTC; <time details> Docs: man:systemd-sysv-generator(8) Tasks: 0 (limit: 2295) Memory: 0B CGroup: /system.slice/jenkins.service
Open Firewall Port 8080:
To access the Jenkins UI, allow traffic on port 8080:
sudo ufw allow 8080
Confirm Firewall Status:
sudo ufw status
Firewall Note
If the firewall is inactive, that is acceptable for a demo environment. In a production environment, ensure the firewall settings limit access to only trusted IP addresses.
Exit SSH Session:
exit
Your terminal will indicate that the connection has been closed.
Access Jenkins:
Open your web browser and navigate to:
http://<Your_VM_Public_IP>:8080
If Jenkins is not accessible, verify your network settings in the Azure portal under Networking. Confirm that port 8080 is open. If not, add an inbound security rule.Configure the rule with a source port range of "Any," destination of "Any," and destination port range as 8080:
Name the rule (e.g., "port_8080") and finalize the creation:
Unlocking and Setting Up Jenkins
Unlock Jenkins:
When you first access the Jenkins UI, you'll be prompted to unlock Jenkins using the initial admin password. Retrieve the password from your server with:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Example output:
f3800843e411475eab7d1d18eb1bf94c
Complete the Setup:
- Copy the password from the terminal and paste it into the Jenkins setup screen.
- Choose to install the suggested plugins.
- When installation is complete, create your first admin user (e.g., Michael). Provide a username, password, full name, and optionally an email address.
Configure the Jenkins Instance:
If you do not have a DNS record, simply use your VM's IP address in the instance configuration screen.
Finalize the Setup:
After saving your configuration, you will see the Jenkins dashboard.
Conclusion
You have successfully installed and configured Jenkins on an Ubuntu VM using Microsoft Azure. This step-by-step guide should equip you with the knowledge to deploy Jenkins in various environments.
Happy Coding!
Watch Video
Watch video content
Practice Lab
Practice lab