Install and Configure Jenkins on Ubuntu 22.04: Best Automation Platform

Posted on

Install and Configure Jenkins on Ubuntu 22.04: Best Automation Platform

Install and Configure Jenkins on Ubuntu 22.04: Best Automation Platform

In this guide, you will learn to Install and Configure Jenkins on Ubuntu 22.04. Jenkins is a Java-based open-source automation platform with plugins designed for continuous integration. It is used to continually create and test software projects, making it easier for developers and DevOps engineers to integrate changes to the project and for consumers to get a new build. It also enables you to release your software continuously by interacting with various testing and deployment methods.

Organizations may use Jenkins to automate and speed up the software development process. Jenkins incorporates a variety of development life-cycle operations, such as build, document, test, package, stage, deploy, static analysis, and more.

Now follow the guide steps below on the Orcacore website to Install and Configure Jenkins on Ubuntu 22.04.

To set up Jenkins, log in to your server as a non-root user with sudo privileges and follow the steps below. For an initial setup, you can visit this guide on Initial Server Setup with Ubuntu 22.04.

1. Install OpenJDK on Ubuntu 22.04

Because Jenkins is written in Java, you must have it installed on your server. First, update your local package index with the following command:

sudo apt update

Then, use the following command to install OpenJDK:

sudo apt install openjdk-11-jdk -y

Verify your Java installation by checking its version:

java -version
**Output**
openjdk version "11.0.18" 2023-01-17
OpenJDK Runtime Environment (build 11.0.18+10-post-Ubuntu-0ubuntu122.04)
OpenJDK 64-Bit Server VM (build 11.0.18+10-post-Ubuntu-0ubuntu122.04, mixed mode, sharing)

2. Installation Steps of Jenkins on Ubuntu 22.04

At this point, you need to add the Jenkins GPG key and Enable its repository. To do this, follow the steps below.

Add Jenkins GPG key

Jenkins packages aren’t available in the default Ubuntu 22.04 repository. So you need to add it manually to your server.

First, add the Jenkins GPG key by using the following curl command:

curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee 
  /usr/share/keyrings/jenkins-keyring.asc > /dev/null

Add Jenkins Repository

Now you need to add the Jenkins repo to your Ubuntu server by using the following command:

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

Run System Update

At this point, run the system update by using the command below:

sudo apt update

Install Jenkins

Finally, use the following command to install Jenkins on Ubuntu 22.04:

sudo apt install jenkins -y

Jenkins Service Status

When your installation is completed, your Jenkis service must be started on your Ubuntu 22.04 automatically. To confirm it, run the command below:

sudo systemctl status jenkins
**Output**
● jenkins.service - Jenkins Continuous Integration Server
     Loaded: loaded (/lib/systemd/system/jenkins.service; enabled; vendor preset>
     Active: **active** (**running**) since Sat 2023-04-29 10:13:31 UTC; 5min ago
   Main PID: 4680 (java)
      Tasks: 44 (limit: 4575)
     Memory: 1.2G
        CPU: 1min 14.113s
     CGroup: /system.slice/jenkins.service
             └─4680 /usr/bin/java -Djava.awt.headless=true -jar /usr/share/java>

If the service is not running or active, you can use the following command:

sudo systemctl enable --now jenkins

Jenkins Administrator password

To access the Jenkins dashboard, you need your Jenkins admin password. By default, Jenkins’s password is available in the /var/lib/jenkins/secrets/. To find it, you can use the following command:

sudo cat /var/lib/jenkins/secrets/initialAdminPassword
**Output**
ad706b82673846dcb928468e6853f10c

3. Jenkins Configuration through Web Interface

At this point, you can access your Jenkins web interface by typing your server’s IP address in your web browser followed by 8080:

http://<your-server-ip>:8080

You will see the Unlock Jenkins page. Enter your Jenkins initial admin password and click Continue.

Unlock jenkins

Next, you should choose which Jenkins plugins you want to install on Ubuntu 22.04. You can select plugins or the recommended ones. Here we choose Install suggested plugins.

Install Jenkins plugins

This will take some time to complete.

Then, you can create your first admin user. You can use this to log in and use Jenkins in the future.

Jenkins admin user

Access Jenkins Dashboard on Ubuntu 22.04

Finally, after following the other few steps you will have your Dashboard to start creating projects for testing and developing along with your developer’s Team.

Jenkins instance configuration
Start using jenkins on Ubuntu 22.04

You should see your Jenkins dashboard:

Jenkins dashboard Ubuntu 22.04

For more information, you can visit the Jenkins Docs page.

Conclusion

Jenkins is simple to set up and customize. Jenkins has many plugins that give it a lot of versatility. It delivers code instantaneously, generates a report after deployment, highlights errors in code or tests, and detects and resolves various issues in near real time. It’s also ideal for integration because it’s all done automatically.

Hope you enjoy this guide on Install and Configure Jenkins on Ubuntu 22.04. This walkthrough should help you get Install and Configure Jenkins on Ubuntu 22.04 with ease.

You may also interested in these articles:

  • Check and Install Security Updates on Ubuntu 22.04
  • Install Bitwarden on Ubuntu 20.04
  • Install Siege Stress Test on Ubuntu 20.04

Please subscribe to us on Facebook, YouTube, and Instagram.

Alternative Solutions for Installing Jenkins on Ubuntu 22.04

While the above method using the official Jenkins repository is the most common and recommended approach, there are alternative methods to Install and Configure Jenkins on Ubuntu 22.04. Here are two different approaches:

1. Using Docker

Docker provides a containerized environment that simplifies application deployment. This method is particularly useful for isolating Jenkins and its dependencies, preventing conflicts with other software on your system.

Explanation:

Docker allows you to run Jenkins in a container, which is a lightweight, isolated environment. This means Jenkins and its dependencies are packaged together, ensuring consistency across different environments. It eliminates the need to manually install Java or manage Jenkins’ service.

Steps:

  1. Install Docker:

    sudo apt update
    sudo apt install docker.io -y
    sudo systemctl start docker
    sudo systemctl enable docker
  2. Pull the Jenkins Docker Image:

    sudo docker pull jenkins/jenkins:lts
  3. Run the Jenkins Container:

    sudo docker run -d -p 8080:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts
    • -d: Runs the container in detached mode (background).
    • -p 8080:8080: Maps port 8080 on the host to port 8080 in the container (for web access).
    • -p 50000:50000: Maps port 50000 on the host to port 50000 in the container (for Jenkins agents).
    • -v jenkins_home:/var/jenkins_home: Creates a named volume to persist Jenkins data. This is crucial; otherwise, your Jenkins configuration will be lost when the container stops.
    • jenkins/jenkins:lts: Specifies the Jenkins image to use (Long Term Support version).
  4. Access Jenkins:

    Open your web browser and navigate to http://<your-server-ip>:8080.

  5. Retrieve the Initial Admin Password:

    Since Jenkins is running in a container, the initial admin password is not directly accessible on the host file system. You need to access it through the container’s logs:

    sudo docker logs <container_id> 2>&1 | grep "Jenkins initial setup is required" | sed 's/.*initialAdminPassword: //'

    Replace <container_id> with the actual container ID, which can be found by running sudo docker ps.

    This command retrieves the container logs, filters for the line containing the initial admin password, and extracts the password using sed.

  6. Proceed with the web-based configuration as described in the original article.

2. Using a WAR File

Another way to Install and Configure Jenkins on Ubuntu 22.04 is to download the Jenkins WAR (Web Application Archive) file and run it directly with Java. This method provides more control over the Jenkins environment but requires manual configuration.

Explanation:

This method involves downloading the standalone Jenkins WAR file and executing it using the java -jar command. It’s a more manual approach but avoids using package managers or containerization.

Steps:

  1. Install Java (if not already installed):

    sudo apt update
    sudo apt install openjdk-11-jdk -y
  2. Download the Jenkins WAR File:

    Visit the Jenkins downloads page (https://www.jenkins.io/download/) and download the latest stable WAR file. Alternatively, use wget:

    wget https://get.jenkins.io/war-stable/latest/jenkins.war
  3. Run the WAR File:

    java -jar jenkins.war --httpPort=8080
    • --httpPort=8080: Specifies the port on which Jenkins will listen. You can change this to a different port if needed.
  4. Access Jenkins:

    Open your web browser and navigate to http://<your-server-ip>:8080.

  5. Retrieve the Initial Admin Password:

    The initial admin password will be printed to the console where you ran the java -jar command. Look for a line similar to:

    Jenkins initial setup is required. An admin user has been created with the password 'YOUR_PASSWORD'. Please use the following security code to proceed: YOUR_PASSWORD

    Alternatively, the password is also stored in /var/jenkins_home/secrets/initialAdminPassword. This directory is created when the java -jar command is run.

    sudo cat /var/jenkins_home/secrets/initialAdminPassword
  6. Configuration:

    Proceed with the web-based configuration as described in the original article.

Important Considerations for WAR File Method:

  • Background Process: Running java -jar directly will tie up your terminal. To run Jenkins in the background, you can use nohup:

    nohup java -jar jenkins.war --httpPort=8080 &

    This will run Jenkins in the background and redirect output to a file named nohup.out. You can then close your terminal.

  • Service Management: To manage Jenkins as a service (start, stop, restart), you would need to create a systemd service file manually. This is more complex than the package manager installation, which handles this automatically.

These alternative methods offer different ways to Install and Configure Jenkins on Ubuntu 22.04, catering to various needs and preferences. Docker provides isolation and consistency, while the WAR file method offers more granular control. The choice depends on your specific requirements and technical expertise.

Leave a Reply

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