Install Jenkins on Ubuntu 24.04

  1. Install Jenkins

Update and Install Java

Jenkins requires Java, so install OpenJDK:

sudo apt update
sudo apt install openjdk-17-jdk -y

Add Jenkins Repository and Install Jenkins

sudo wget -O /usr/share/keyrings/jenkins-keyring.asc https://pkg.jenkins.io/debian/jenkins.io-2023.key
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
sudo apt update
sudo apt install jenkins -y

Configure Jenkins to Listen Only on Localhost

sudo systemctl edit jenkins

This will open a blank editor. Add the following lines:

[Service]
Environment="JENKINS_LISTEN_ADDRESS=127.0.0.1"

Save the file and restart Jenkins:

sudo systemctl daemon-reload
sudo systemctl restart jenkins

Verify Jenkins is listening only on 127.0.0.1:

sudo ss -tlnp | grep 8080

You should see:

LISTEN 0      50     [::ffff:127.0.0.1]:8080            *:*    users:(("java",pid=5863,fd=8))
  1. Install and Configure Nginx as a Reverse Proxy

Install Nginx

sudo apt install nginx -y

Create an Nginx Configuration for Jenkins

Create a new server block:

sudo nano /etc/nginx/sites-available/jenkins

Add the following configuration:

server {
    listen 80;
    server_name jenkins.maksonlee.com;

    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_buffering off;
        proxy_request_buffering off;
    }
}

Enable the Configuration

sudo ln -s /etc/nginx/sites-available/jenkins /etc/nginx/sites-enabled/

Test Nginx Configuration

sudo nginx -t

If the test passes, restart Nginx:

sudo systemctl restart nginx

Now, you should be able to access Jenkins via http://jenkins.maksonlee.com.

  1. Secure Jenkins with SSL Using Let’s Encrypt

Install Certbot and SSL Plugin

sudo apt install certbot python3-certbot-nginx -y

Obtain SSL Certificate

Run the following command to get an SSL certificate and configure Nginx:

sudo certbot --nginx -d jenkins.maksonlee.com

Follow the on-screen instructions. Certbot will automatically configure Nginx to use SSL.

Verify SSL Renewal

sudo certbot renew --dry-run

This ensures automatic certificate renewal is working.

  1. Access Jenkins Securely

Now, you can access Jenkins securely via:

https://jenkins.maksonlee.com
  1. Unlock Jenkins

To get the initial admin password, run:

sudo cat /var/lib/jenkins/secrets/initialAdminPassword

Copy and paste this password into the Jenkins setup wizard at

https://jenkins.maksonlee.com

Leave a Comment

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

Scroll to Top