(Last Updated On: April 9, 2019)

How can I install Jenkins on CentOS 7?. Jenkins is an open source automation server written in Java that was designed to automate repetitive tasks that are often encountered in continuous integration and delivery of software.

For Ubuntu, see: How to Install Jenkins on Ubuntu 18.04

For Arch Linux: How to Install and Configure Jenkins on Arch Linux

For Docker Container: Running Jenkins Server in Docker Container with Systemd

Jenkins is typically run as a standalone application in its own process with the built-in Java servlet container/application server (Jetty).

Minimum Hardware requirements:

  • 256 MB of RAM, 1 GB+ recommended
  • GB of drive space (although 10 GB is a recommended minimum if running Jenkins as a Docker container)

Step 1: Install Jenkins on CentOS 7

Jenkins requires Java in order to run, but CentOS 7 doesn’t include it by default. To install the Open Java Development Kit (OpenJDK) run the following:

sudo yum -y install epel-release
sudo yum install java-1.8.0-openjdk

Check to make sure that you have java installed by running:

$ java -version
openjdk version "1.8.0_201"
OpenJDK Runtime Environment (build 1.8.0_201-b09)
OpenJDK 64-Bit Server VM (build 25.201-b09, mixed mode)

Start by importing the repository key from Jenkins

sudo rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key

After importing the key, add the repository to the system

sudo yum -y install wget
sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo

Then install Jenkins package using yum:

sudo yum -y install jenkins

If you need the LTS release only, run the following commands instead:

sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo
sudo rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key
sudo yum -y install jenkins

You can now start Jenkins service using:

sudo systemctl start jenkins
sudo systemctl enable --now jenkins

A check on status should return running state

$ sudo systemctl status jenkins
● jenkins.service - LSB: Jenkins Automation Server
Loaded: loaded (/etc/rc.d/init.d/jenkins; bad; vendor preset: disabled)
Active: active (exited) since Thu 2019-03-07 09:23:25 CET; 4s ago
Docs: man:systemd-sysv-generator(8)
Process: 15039 ExecStart=/etc/rc.d/init.d/jenkins start (code=exited, status=0/SUCCESS)
Mar 07 09:23:24 centos-2gb-nbg1-1 systemd[1]: Starting LSB: Jenkins Automation Server…
Mar 07 09:23:25 centos-2gb-nbg1-1 runuser[15044]: pam_unix(runuser:session): session opened for user jenkins by (uid=0)
Mar 07 09:23:25 centos-2gb-nbg1-1 jenkins[15039]: Starting Jenkins [ OK ]
Mar 07 09:23:25 centos-2gb-nbg1-1 systemd[1]: Started LSB: Jenkins Automation Server.

Enable port 8080/tcp on the firewall

sudo firewall-cmd --add-port=8080/tcp --permanent
sudo firewall-cmd --reload
sudo firewall-cmd --list-all

The service should be listening on port 8080

# ss -tunelp | grep 8080
tcp LISTEN 0 50 :::8080 :::*

Step 2: Unlock Jenkins on CentOS 7

Browse to the URL http://[serverip|hostname]:8080 to access web installation wizard.

When you first access a new Jenkins instance, you are asked to unlock it using an automatically generated password.

Get the password from

$ cat /var/lib/jenkins/secrets/initialAdminPassword
75a6155d70b7435c9b382197c823aa35

Copy-paste the automatically-generated alphanumeric password into the Administrator password field and click Continue.

Next is to create an admin user account used to manage the Jenkins server.

Select plugins to install in the next page.

Step 3: Configure Nginx and SSL (Optional)

It is recommended to access Jenkins Server behind a Proxy server secured with SSL certificate. Check below guide.

Configure Jenkins behind Nginx reverse proxy and Let’s Encrypt SSL

Step 4: Configure User Roles on Jenkins

By default, Jenkins user policy allows logged in users to access anything. This should not be the case and you need to set proper user policies. Check out our Jenkins policy and user management guide below.

How to Manage Users and Roles in Jenkins

Let other users Login with their credentials and assign them roles which define what they can do on Jenkins server.

Conclusion

Enjoy automating your jobs with Jenkins. For more reading, check Official Documentation. We will publish more articles on Jenkins and CI/CD.

Also check:

How to Manage Users and Roles in Jenkins

Configure Jenkins behind Nginx reverse proxy and Let’s Encrypt SSL

How to Configure Jenkins FreeIPA LDAP Authentication

Running Jenkins Server in Docker Container with Systemd

Install and Configure Hashicorp Vault Server on Ubuntu / CentOS / Debian

How to Install Terraform on Ubuntu / CentOS