DEV Community

Janak Shrestha
Janak Shrestha

Posted on

Day 68: Set Up Jenkins Server – A Complete Guide

The DevOps team at xFusionCorp Industries is initiating the setup of CI/CD pipelines and has decided to utilize Jenkins as their server. Execute the task according to the provided requirements:

  1. Install Jenkins on the jenkins server using the apt utility only, and start it using the service command.
  2. If you face a timeout issue while starting the Jenkins service, first check the service status with service jenkins status
  3. Then review the logs in /var/log/jenkins/jenkins.log to identify the cause.

  4. Jenkin's admin user name should be theadmin, password should be Adm!n321, full name should be Ravi and email should be [email protected].

Note:

  1. To access the jenkins server, connect from the jump host using the root user with the password S3curePass.
  2. After Jenkins server installation, click the Jenkins button on the top bar to access the Jenkins UI and follow on-screen instructions to create an admin user.

Understanding Jenkins

What is Jenkins?

Jenkins is a Java-based automation server that facilitates continuous integration and continuous delivery (CI/CD). It provides hundreds of plugins to support building, deploying, and automating any project.

Why Use Jenkins?

Feature Benefit
Automation Automates build, test, and deployment processes
Extensibility Over 2,000 plugins available
Distributed Builds Supports master-agent architecture
Integration Works with Git, Docker, Kubernetes, and more
Open Source Free to use with a large community

What We Will Build

Task Overview

Component Specification
Server Jenkins Server (Ubuntu 24.04)
Java Version OpenJDK 21
Jenkins Version 2.568.3
Port 8080
Admin User theadmin
Password Adm!n321
Full Name Ravi
Email [email protected]

Architecture Diagram

┌─────────────────────────────────────────────────────────────────────────────┐
│                         Jenkins Server (Ubuntu 24.04)                      │
│                                                                              │
│  ┌────────────────────────────────────────────────────────────────────────┐ │
│  │  Jenkins Installation                                                 │ │
│  │  - Installed via apt                                                  │ │
│  │  - Version: 2.568.3                                                   │ │
│  │  - Port: 8080                                                         │ │
│  └────────────────────────────────────────────────────────────────────────┘ │
│                                    │                                         │
│                                    ▼                                         │
│  ┌────────────────────────────────────────────────────────────────────────┐ │
│  │  Java Runtime Environment                                             │ │
│  │  - OpenJDK 21                                                         │ │
│  │  - Required for Jenkins to run                                        │ │
│  └────────────────────────────────────────────────────────────────────────┘ │
│                                    │                                         │
│                                    ▼                                         │
│  ┌────────────────────────────────────────────────────────────────────────┐ │
│  │  Jenkins Configuration                                                │ │
│  │  - Admin User: theadmin                                               │ │
│  │  - Password: Adm!n321                                                 │ │
│  │  - Full Name: Ravi                                                    │ │
│  │  - Email: [email protected]                       │ │
│  └────────────────────────────────────────────────────────────────────────┘ │
│                                    │                                         │
│                                    ▼                                         │
│            https://8080-port-u5auld5niwwzzrcr.labs.kodekloud.com                             │
└─────────────────────────────────────────────────────────────────────────────┘
Enter fullscreen mode Exit fullscreen mode

SSH to Jenkins Server

# Connect from jump host
ssh root@jenkins
# Password: S3curePass
Enter fullscreen mode Exit fullscreen mode

Update System Packages

apt update
apt upgrade -y
Enter fullscreen mode Exit fullscreen mode

Install Java 21

Jenkins requires Java 21 or 25. Earlier versions like Java 11 will cause compatibility issues.

# Install Java 21
apt install -y openjdk-21-jdk

# Verify Java installation
java -version
Enter fullscreen mode Exit fullscreen mode

Output:

openjdk version "21.0.12" 2026-07-21
OpenJDK Runtime Environment (build 21.0.12+8-1-24.04-Ubuntu)
OpenJDK 64-Bit Server VM (build 21.0.12+8-1-24.04-Ubuntu, mixed mode, sharing)
Enter fullscreen mode Exit fullscreen mode

Remove Older Java Versions

If Java 11 is installed, remove it to avoid conflicts.

# Check installed Java versions
dpkg -l | grep -i jdk

# Remove Java 11
apt purge -y openjdk-11-*

# Verify Java 21 is still installed
java -version
Enter fullscreen mode Exit fullscreen mode

Install Jenkins

Add the Jenkins repository and install the package.

# Add Jenkins repository key
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | apt-key add -

# Add Jenkins repository
echo "deb https://pkg.jenkins.io/debian-stable binary/" > /etc/apt/sources.list.d/jenkins.list

# Update package list
apt update

# Install Jenkins
apt install -y jenkins
Enter fullscreen mode Exit fullscreen mode

Output:

Setting up jenkins (2.568.3) ...
Enter fullscreen mode Exit fullscreen mode

Step 5: Start Jenkins Service

# Start Jenkins
service jenkins start

# Check status
service jenkins status

# Verify port 8080 is listening
netstat -tulpn | grep 8080
Enter fullscreen mode Exit fullscreen mode

Output:

tcp6       0      0 :::8080                 :::*                    LISTEN      5515/java
Enter fullscreen mode Exit fullscreen mode

Retrieve Initial Admin Password

# Get the initial admin password
cat /var/lib/jenkins/secrets/initialAdminPassword
Enter fullscreen mode Exit fullscreen mode

Output:

5da7d6a2ff9544e78d48dd55a36813ea
Enter fullscreen mode Exit fullscreen mode

Access Jenkins UI

  1. Click the Jenkins button on the top bar
  2. Or access via browser: https://8080-port-u5auld5niwwzzrcr.labs.kodekloud.com/
  3. Enter the initial admin password

Create Admin User

In the Jenkins UI setup wizard:

  1. Select Install suggested plugins
  2. Wait for plugin installation to complete
  3. Create the admin user with the following details:
  4. Click Save and Continue
  5. Set the Jenkins URL (keep default or use provided URL)
  6. Click Save and Finish

Verify Jenkins is Ready

Once the setup is complete, you will see the Jenkins dashboard:


Troubleshooting

Jenkins Fails to Start

# Check Jenkins logs
tail -50 /var/log/jenkins/jenkins.log

# Check Java version
java -version

# Start Jenkins manually
java -jar /usr/share/java/jenkins.war --httpPort=8080
Enter fullscreen mode Exit fullscreen mode

Port 8080 Already in Use

# Check what is using port 8080
netstat -tulpn | grep 8080

# Kill the process
fuser -k 8080/tcp

# Start Jenkins again
service jenkins start
Enter fullscreen mode Exit fullscreen mode

Missing Initial Admin Password

# The initial password is stored here
cat /var/lib/jenkins/secrets/initialAdminPassword

# If not found, check Jenkins logs
tail -50 /var/log/jenkins/jenkins.log | grep -i password
Enter fullscreen mode Exit fullscreen mode

Java Version Incompatibility

# Check Jenkins logs for Java version errors
tail -50 /var/log/jenkins/jenkins.log

# Install correct Java version
apt install -y openjdk-21-jdk

# Verify default Java
update-alternatives --config java
Enter fullscreen mode Exit fullscreen mode

Jenkins Configuration Files

File Purpose
/etc/default/jenkins Main configuration (port, Java options)
/var/lib/jenkins/ Jenkins home directory
/var/log/jenkins/jenkins.log Jenkins logs
/var/lib/jenkins/secrets/initialAdminPassword Initial admin password
/usr/share/java/jenkins.war Jenkins WAR file

Key Takeaways

1. Java Version Matters

Jenkins requires Java 21 or 25. Using an older version like Java 11 will prevent Jenkins from starting.

2. Initial Admin Password

The initial admin password is stored in /var/lib/jenkins/secrets/initialAdminPassword. This is required for the first login.

3. Service Management

On Ubuntu, Jenkins can be managed using the service command:

service jenkins start
service jenkins stop
service jenkins status
service jenkins restart
Enter fullscreen mode Exit fullscreen mode

4. Port Configuration

Jenkins runs on port 8080 by default. This can be changed in /etc/default/jenkins by modifying the HTTP_PORT variable.


Useful Commands Reference

Command Purpose
service jenkins start Start Jenkins
service jenkins stop Stop Jenkins
service jenkins status Check Jenkins status
service jenkins restart Restart Jenkins
cat /var/lib/jenkins/secrets/initialAdminPassword Get initial admin password
tail -f /var/log/jenkins/jenkins.log View logs in real-time
java -version Check Java version
`netstat -tulpn \ grep 8080`
apt install -y jenkins Install Jenkins
apt purge -y openjdk-11-* Remove Java 11

Jenkins is now ready for use. The next steps would include installing plugins, configuring build jobs, and setting up CI/CD pipelines. This setup provides a foundation for automating software delivery processes in a DevOps environment.

Top comments (0)