Install and Configure Jenkins on Debian 11 with Best Steps

Posted on

Install and Configure Jenkins on Debian 11 with Best Steps

Install and Configure Jenkins on Debian 11 with Best Steps

This tutorial is designed to guide you through the process of Install and Configure Jenkins on Debian 11. Jenkins is a powerful open-source continuous integration/continuous delivery and deployment (CI/CD) automation DevOps tool written in Java. Its primary function is to implement CI/CD workflows, which are commonly referred to as pipelines.

Pipelines automate various critical processes, including testing and reporting on code changes in real-time, facilitating the integration of different code branches into a main branch. They also rapidly identify defects in the codebase, build the software, automate the testing of builds, prepare the code for deployment (delivery), and ultimately deploy code to containers, virtual machines, bare metal servers, and cloud environments.

Let’s walk through the steps required to Install and Configure Jenkins on Debian 11.

To begin the Jenkins setup on Debian 11, log in to your server as a non-root user with sudo privileges. If you haven’t already set up a user with sudo privileges, you can refer to our guide on Initial Server Setup with Debian 11.

1. Install OpenJDK on Debian 11

Since Jenkins is written in Java, you need to have a Java Development Kit (JDK) installed on your server. OpenJDK 11 is a suitable choice.

First, update your local package index using the following command:

sudo apt update

Next, install OpenJDK 11 with the following command:

sudo apt install openjdk-11-jdk -y

To verify that Java is correctly installed, check the version:

java -version

You should see output similar to this:

**Output**
openjdk version "11.0.18" 2023-01-17
OpenJDK Runtime Environment (build 11.0.18+10-post-Debian-1deb11u1)
OpenJDK 64-Bit Server VM (build 11.0.18+10-post-Debian-1deb11u1, mixed mode, sharing)

2. Install Jenkins deployment tool on Debian 11.

To install the Jenkins deployment tool, you’ll need to add the Jenkins GPG key and enable its repository. Follow the steps outlined below.

Add Jenkins GPG key

Jenkins packages are not available in the default Debian 11 repository. Therefore, you need to add the Jenkins repository manually.

First, ensure that curl is installed on your Debian 11 system:

sudo apt install curl -y

Then, add the Jenkins GPG key 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, add the Jenkins repository to your Debian server using this 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

Update the package list to include the newly added Jenkins repository:

sudo apt update

Command To install Jenkins

Finally, install Jenkins on Debian 11 using the following command:

sudo apt install jenkins -y

Jenkins Service Status

After the installation is complete, the Jenkins service should start automatically. To verify its status, run:

sudo systemctl status jenkins

You should see output similar to this:

**Output**
● jenkins.service - Jenkins Continuous Integration Server
     Loaded: loaded (/lib/systemd/system/jenkins.service; enabled; vendor preset: enabled)
     Active: **active** (**running**) since Thu 2023-04-13 06:08:52 EDT; 1min 24s ago
   Main PID: 5222 (java)
      Tasks: 43 (limit: 4679)
     Memory: 1.2G
        CPU: 1min 9.528s
     CGroup: /system.slice/jenkins.service
             └─5222 /usr/bin/java -Djava.awt.headless=true -jar /usr/share/java/jenkins.war --webroot=%W --httpPort=8080

If the service is not running, you can start and enable it with:

sudo systemctl enable --now jenkins

Jenkins Administrator password

To access the Jenkins dashboard, you’ll need the initial administrator password. By default, Jenkins stores this password in the /var/lib/jenkins/secrets/initialAdminPassword file. You can retrieve it using:

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

The output will be a long alphanumeric string:

**Output**
91d9db64647b4260b457fa1c17765159

3. Configure Jenkins through Web Interface

Now, you can access the Jenkins web interface by navigating to your server’s IP address in your web browser, followed by port 8080:

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

You will be presented with the "Unlock Jenkins" page. Enter the Jenkins initial admin password you retrieved in the previous step and click "Continue."

Unlock jenkins

Next, you’ll be prompted to choose which Jenkins plugins you want to install. You can either select specific plugins or install the recommended ones. Choose "Install suggested plugins."

Install Jenkins plugins

The installation process will take some time to complete.

After the plugins are installed, you can create your first administrator user. Use this user to log in and manage Jenkins in the future.

Jenkins admin user

Access Jenkins Dashboard on Debian 11

After completing the setup steps, you’ll have access to the Jenkins dashboard. From here, you can start creating projects for testing and development with your team.

Jenkins instance configuration
Start using jenkins on Debian 11

You should see your Jenkins dashboard, which looks like this:

Jenkins dashboard debian 11
Jenkins Deployment Tool Dashboard

For further information, refer to the Jenkins Docs page.

Conclusion

Install and Configure Jenkins on Debian 11 successfully and you have Jenkins helps teams automate repetitive tasks, enhance collaboration, and ensure faster, more reliable software delivery. You have now learned how to Install and Configure Jenkins on Debian 11.

Here are some other articles you might be interested in:

Install OTRS Community Edition on Debian 11

Set up ProcessWire CMS on Debian 11

How To Install OpenSSL 3 on Debian 11

Alternative Solutions for Installing Jenkins on Debian 11

While the steps outlined above provide a straightforward method for installing Jenkins on Debian 11, there are alternative approaches that might be more suitable depending on your specific needs and environment. Here are two different ways to solve the problem:

1. Using Docker

Docker provides a containerization platform that allows you to run applications in isolated environments. Installing Jenkins using Docker simplifies the process and ensures consistency across different environments.

Explanation:

Docker containers encapsulate all the dependencies required for an application to run, including the operating system, libraries, and runtime environment. This eliminates compatibility issues and simplifies deployment. With Docker, you can quickly spin up a Jenkins instance without manually installing Java, configuring repositories, or managing system services.

Steps:

  1. Install Docker: If you haven’t already installed Docker on your Debian 11 system, you can do so using the following commands:
sudo apt update
sudo apt install docker.io -y
sudo systemctl start docker
sudo systemctl enable docker
  1. Pull the Jenkins Docker Image: Obtain the official Jenkins Docker image from Docker Hub:
sudo docker pull jenkins/jenkins:lts
  1. Run the Jenkins Container: Start a new Jenkins container with the following command:
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 (in the background).
*   `-p 8080:8080`: Maps port 8080 on the host machine to port 8080 in the container (Jenkins web interface).
*   `-p 50000:50000`: Maps port 50000 on the host machine to port 50000 in the container (Jenkins agent communication).
*   `-v jenkins_home:/var/jenkins_home`: Creates a named volume `jenkins_home` to persist Jenkins data.
  1. Access Jenkins: Open your web browser and navigate to http://<your-server-ip>:8080. Follow the on-screen instructions to unlock Jenkins using the initial administrator password, which can be found by inspecting the container logs or within the volume.

This Docker-based approach streamlines the Install and Configure Jenkins on Debian 11 process.

2. Using a Configuration Management Tool (Ansible)

Ansible is an open-source automation tool that enables you to provision and manage infrastructure as code. Using Ansible to install Jenkins allows for repeatable and consistent deployments across multiple servers.

Explanation:

Ansible uses playbooks written in YAML to define the desired state of your infrastructure. These playbooks can automate tasks such as installing packages, configuring services, and deploying applications. By creating an Ansible playbook for Jenkins installation, you can easily deploy Jenkins to multiple Debian 11 servers with a single command.

Steps:

  1. Install Ansible: If Ansible is not installed on your control machine, install it using pip:
sudo apt update
sudo apt install python3-pip -y
pip3 install ansible
  1. Create an Ansible Playbook: Create a YAML file (e.g., jenkins_install.yml) with the following content:
---
- hosts: all
  become: true
  tasks:
    - name: Install OpenJDK 11
      apt:
        name: openjdk-11-jdk
        state: present
        update_cache: yes

    - name: Add Jenkins GPG key
      apt_key:
        url: https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
        state: present

    - name: Add Jenkins repository
      apt_repository:
        repo: deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian-stable binary/
        state: present
        filename: jenkins

    - name: Install Jenkins
      apt:
        name: jenkins
        state: present
        update_cache: yes

    - name: Ensure Jenkins is running and enabled
      systemd:
        name: jenkins
        state: started
        enabled: yes
  1. Run the Playbook: Execute the Ansible playbook using the ansible-playbook command:
ansible-playbook -i <inventory_file> jenkins_install.yml
Replace `<inventory_file>` with the path to your Ansible inventory file, which specifies the target servers.

This Ansible-based approach provides an automated and repeatable way to Install and Configure Jenkins on Debian 11, especially in environments with multiple servers. The Install and Configure Jenkins on Debian 11 process can be automated with the mentioned method.

Leave a Reply

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