How to Install Jenkins on CentOS 7 or RHEL 7

In this article, you’ll come to know how to install Jenkins on CentOS 7 or RHEL 7. Jenkins is a very popular continuous integration and continuous delivery (CI/CD) tool used for development, deployment, and automation. 

Jenkins is a popular open-source automation server that allows developers to automate the process of building, testing, and deploying software. In this tutorial, we will walk through the steps of installing Jenkins on CentOS 7 or RHEL 7.

Prerequisite:

Before installing Jenkins, you need to make sure that your server meets the following requirements:

  • A server running CentOS 7 or RHEL 7
  • SSH access with root or sudo privileges

Steps to install Jenkins on CentOS 7 or RHEL 7

Step 1: Install OpenJDK 8 package

sudo yum install java-1.8.0-openjdk-devel

How to Install Jenkins on CentOS 7 or RHEL 7

Article on Java install/upgrade .

Step 2: Install Jenkins repository

curl --silent --location http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo | sudo tee /etc/yum.repos.d/jenkins.repo
sudo rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key

you can also download the Jenkins package.

Sample output:

[root@centos ~]# curl --silent --location http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo | sudo tee /etc/yum.repos.d/jenkins.repo

[jenkins]
name=Jenkins-stable
baseurl=http://pkg.jenkins.io/redhat-stable
gpgcheck=1

[root@centos ~]#
[root@centos ~]# sudo rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key

Verify yum repository:

[root@centos ~]# cat /etc/yum.repos.d/jenkins.repo
[jenkins]
name=Jenkins-stable
baseurl=http://pkg.jenkins.io/redhat-stable
gpgcheck=1
[root@centos ~]#

Step 3: Install stable Jenkins on CentOS 7

sudo yum install jenkins 

How to Install Jenkins on CentOS 7 or RHEL 7

Sample output:

[root@centos yum.repos.d]# sudo yum install jenkins -y

Loaded plugins: fastestmirror, langpacks

Loading mirror speeds from cached hostfile

* base: mirrors.piconets.webwerks.in

* extras: mirrors.piconets.webwerks.in

* updates: mirrors.piconets.webwerks.in

jenkins | 2.9 kB 00:00:00

Resolving Dependencies

--> Running transaction check

---> Package jenkins.noarch 0:2.277.1-1.1 will be installed

--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================================================

Package Arch Version Repository Size
====================================================================================================================================

Installing:

jenkins noarch 2.277.1-1.1 jenkins 67 M

Transaction Summary
====================================================================================================================================

Install 1 Package

Total size: 67 M

Installed size: 68 M

Downloading packages:

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

Installing : jenkins-2.277.1-1.1.noarch 1/1

Verifying : jenkins-2.277.1-1.1.noarch 1/1

Installed:

jenkins.noarch 0:2.277.1-1.1

Complete!
[root@centos yum.repos.d]#

Step 4: Start the Jenkins service and auto-start on boot

sudo systemctl start jenkins

sudo systemctl enable jenkins

Sample output:

[root@centos ~]# sudo systemctl start jenkins

[root@centos ~]# sudo systemctl enable jenkins

jenkins.service is not a native service, redirecting to /sbin/chkconfig.

Executing /sbin/chkconfig jenkins on

[root@centos ~]#

Step 5: Verify the status of Jenkins

systemctl status jenkins

How to Install Jenkins on CentOS 7 or RHEL 7

Step 6: Configure the firewall and allow an 8080 port

By default, Jenkins runs on port 8080. If you have a firewall enabled on your system, you need to open port 8080 to allow external access to Jenkins.

Use the following command to open port 8080 and reload the firewall service:

sudo firewall-cmd --permanent --zone=public --add-port=8080/tcp
sudo firewall-cmd --reload

Sample output:

[root@centos ~]# sudo firewall-cmd --permanent --zone=public --add-port=8080/tcp
success

[root@centos ~]# sudo firewall-cmd --reload
success

Step 7: Configure Jenkins on CentOS or RHEL

Access Jenkins Web Interface: Open a web browser and navigate to http://your_server_ip:8080. Replace your_server_ip with the actual IP address of your server.

http://your_ip_or_domain:8080

7.1: Unlock Jenkins

How to Install Jenkins on CentOS 7 or RHEL 7

When you access Jenkins for the first time (after installation) it will ask you for the password. And to know the password run the below command, and you will see a 32-character alphanumeric password.

Retrieve the Jenkins unlock key from the server by running:

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

Copy the password and paste it into the Jenkins Administrator section.

How to Install Jenkins on CentOS 7 or RHEL 7

On the Next page, Jenkins will ask you to choose/install the suggested plugins or the select most suitable/specific plugins.

For this blog, I choose “suggested plugins” to continue the plugin’s installation process.

7.2: Customize Jenkins

How to Install Jenkins on CentOS 7 or RHEL 7

7.3: Getting Started

How to Install Jenkins on CentOS 7 or RHEL 7

Next, it will ask you to setup the first admin user. Fill in the details, and click on ‘save and continue’.

7.4: Create First Admin User

How to Install Jenkins on CentOS 7 or RHEL 7

In the next steps, you will get the Jenkins URL with the port. Click on ‘save and finish‘

7.5: Instance Configuration

How to Install Jenkins on CentOS 7 or RHEL 7

The next step is to click on ‘start using Jenkins’.

How to Install Jenkins on CentOS 7 or RHEL 7

7.6: Jenkins Dashboard

It will redirect to the Jenkins dashboard.

How to Install Jenkins on CentOS 7 or RHEL 7

Jenkins is now installed and configured. You can start creating and running your Jenkins jobs.

These steps should help you install Jenkins on CentOS 7 or RHEL 7. Adjust any specific configurations based on your requirements.

Conclusion

In this tutorial, we have walked through the steps of installing Jenkins on CentOS 7 or RHEL 7. We have also covered the basic configuration of Jenkins.

Jenkins is a powerful tool that can help you automate your software development process and improve your team’s productivity. With Jenkins, you can automate your builds, tests, and deployments, reducing the time and effort required to release high-quality software.

You have successfully installed Jenkins on CentOS 7 or RHEL 7.

Jenkins Installation FAQs on CentOS 7 and RHEL 7

Q1: What is Jenkins?

A1: Jenkins is an open-source automation server that helps automate the building, testing, and deployment of applications. It facilitates continuous integration and continuous delivery (CI/CD) by automating the repetitive tasks involved in the software development process.

Q2: Why do I need Java to install Jenkins?

A2: Jenkins is a Java-based application, and it requires a Java Runtime Environment (JRE) or Java Development Kit (JDK) to run. Ensure that Java is installed on your system before installing Jenkins.

Q3: How do I check the status of the Jenkins service?

A3: You can check the status of the Jenkins service using the following command:

sudo systemctl status jenkins

Q4: I cannot access the Jenkins web interface. What should I do?

A4: Ensure that the firewall is not blocking the Jenkins port (default is 8080). You can also check the Jenkins logs for any errors:

sudo journalctl -xe | grep jenkins

Q5: What is the default username and password for Jenkins?

A5: During the initial setup, Jenkins generates an unlock key that you need to paste into the web interface. The unlock key is stored in the file:

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

Q6: Can I change the default port for Jenkins?

A6: Yes, you can change the default Jenkins port (8080) in the Jenkins configuration file located at /etc/sysconfig/jenkins. Modify the JENKINS_PORT variable and restart the Jenkins service.

Q7: How do I install additional plugins in Jenkins?

A7: You can install additional plugins through the Jenkins web interface. Navigate to “Manage Jenkins” -> “Manage Plugins” -> “Available” and select the plugins you want to install.

Q8: What do I do if Jenkins fails to start or encounters issues?

A8: Check the Jenkins logs for any error messages:

sudo journalctl -xe | grep jenkins

Additionally, verify that Java is installed correctly and that there are no conflicts with other services on the server.

These FAQs should address common queries that users might have during the installation and setup of Jenkins on CentOS 7 or RHEL 7.

See also:

Jenkins Blogs

Continuous Integration and Continuous Delivery

List of monitoring tools 

Linux Blogs

AWS Cloud Blogs

Database Blogs

DevOps Blogs

Interview Questions & Answers

Docker Blogs

Google Cloud Blogs

Modernize Your Legacy System The DevOps Way