Install and Configure Jenkins on Debian 9 / Ubuntu 16.04 / CentOS 7

Install and Configure Jenkins on Debian 9
Install and Configure Jenkins on Debian 9

Jenkins is an open source automation server, in other words, a continuous integration tool written in Java that helps to automate the repetitive tasks involved in the software development process. Repetitive tasks could be like software build, testing, and deployments. Jenkins can be installed through the system packages (RPM or DEB), Docker, or on any machine with the JRE installed.

Jenkins project was forked from Oracle Hudson project after a dispute in early 2011, but, still each call other as a fork.

Here, this tutorial guides you through the installation of Jenkins on CentOS 7 / Ubuntu 16.04 / Debian 9.

Prerequisites:

Jenkins requires a minimum of Java 7, but you can also install Java 8 which is recommended by Jenkins.

### Ubuntu 16.04 / Debian 9 ###

sudo apt-get -y install openjdk-8-jdk apt-transport-https wget

### CentOS 7 / Fedora  ###

yum -y install java-1.8.0-openjdk wget

If you want to use the Oracle JAVA instead of OpenJDK, then use any one of the links for guidance.

READ: How to install Oracle JDK 8 on CentOS 7 / RHEL 7

READ: How to install Oracle JDK 8 on Ubuntu 16.04

Once the OpenJDK installation is complete, verify the Java version.

java -version

Output:

openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-b12)
OpenJDK 64-Bit Server VM (build 25.131-b12, mixed mode)

Install Jenkins:

Add Jenkins repository:

Let’s add Jenkins repository as the Jenkins is not available on CentOS 7 / Debian 9 / Ubuntu 16.04 base repositories.

Add the Jenkins key to the system.

### Ubuntu 16.04 / Debian 9 ###

wget https://pkg.jenkins.io/debian-stable/jenkins.io.key
sudo apt-key add jenkins.io.key

### CentOS 7 / Fedora ###

rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key

Add the Jenkins repository information on your system.

### Ubuntu 16.04 / Debian 9 ###

echo "deb https://pkg.jenkins.io/debian-stable binary/" | sudo tee /etc/apt/sources.list.d/jenkins.list

### CentOS 7 / Fedora ###

cd /etc/yum.repos.d/
wget https://pkg.jenkins.io/redhat-stable/jenkins.repo

Install Jenkins:

Now, install Jenkins using the following command.

### Ubuntu 16.04 / Debian 9 ###

sudo apt-get update
sudo apt-get -y install jenkins

### CentOS 7 / Fedora ###

yum -y install jenkins

Control Jenkins:

For Ubuntu / Debian, prepend sudo in all your commands.

To start Jenkins, run:

systemctl start jenkins

To stop Jenkins, run:

systemctl stop jenkins

To restart Jenkins, run:

systemctl restart jenkins

To view the status of Jenkins, run:

systemctl status jenkins

To auto start Jenkins service on system boot, run:

systemctl enable jenkins

Firewall:

Configure the firewall so that you can access Jenkins Web port from outside machines.

FirewallD:

firewall-cmd --permanent --add-port=8080/tcp
firewall-cmd --reload

UFW:

ufw allow 8080/tcp
ufw reload

Configure Jenkins:

Jenkins comes with a web interface where you can build, test, and deploy software. Open up a web browser and navigate it to the following URL.

http://your.ip.add.ress:8080

For security reason, Jenkins puts up an initial password in “/var/lib/Jenkins/secrets/initialAdminPassword” file to prevent unauthorized Jenkins installation.

Read the log file and get the password for Jenkins installation.

### Ubuntu 16.04 / Debian 9 ###

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

### CentOS 7 / Fedora ###

cat /var/lib/jenkins/secrets/initialAdminPassword

Copy and Paste the password on Jenkins wizard, and then click on Continue.

Install and Configure Jenkins on Debian 9 - Unlock Jenkins
Install and Configure Jenkins on Debian 9 – Unlock Jenkins

You can either install suggested plugins or install the most suitable one for your needs.

Install and Configure Jenkins on Debian 9 - Customize Jenkins
Install and Configure Jenkins on Debian 9 – Customize Jenkins

Wait for the plugins installation to complete.

Install and Configure Jenkins on Debian 9 - Installing Jenkins Plugins
Install and Configure Jenkins on Debian 9 – Installing Jenkins Plugins

Create the first admin user for Jenkins.

Install and Configure Jenkins on Debian 9 - Create Admin User
Install and Configure Jenkins on Debian 9 – Create Admin User

Jenkins is now ready for building software. Click on “Start using Jenkins“.

Install and Configure Jenkins on Debian 9 - Installation Complete
Install and Configure Jenkins on Debian 9 – Installation Complete

Jenkins web portal:

Install and Configure Jenkins on Debian 9 - Jenkins Web Portal
Install and Configure Jenkins on Debian 9 – Jenkins Web Portal

Create your first Jenkins project:

Let’s create a sample build using shell command. To do that, go to Jenkins Web Portal –> New Item or create new jobs.

Install and Configure Jenkins on Debian 9 - New Project
Install and Configure Jenkins on Debian 9 – New Project

Name your project and then select “Freestyle project“, then click OK.

Install and Configure Jenkins on Debian 9 - Creating Project
Install and Configure Jenkins on Debian 9 – Creating Project

On the project configuration page, scroll down and choose “Execute shell” in the “Build” section.

Install and Configure Jenkins on Debian 9 - Execute Shell
Install and Configure Jenkins on Debian 9 – Execute Shell

Enter a shell command to execute while building the project.

echo "This is $JOB_NAME"
Install and Configure Jenkins on Debian 9 - Shell Build
Install and Configure Jenkins on Debian 9 – Shell Build

Click on “SAVE

The project is now ready to build. Click on “Build Now” in the left pane to build the project.

Install and Configure Jenkins on Debian 9 - First Project
Install and Configure Jenkins on Debian 9 – First Project

Click on “Console Icon” to see the output of your build.

Install and Configure Jenkins on Debian 9 - Building Project
Install and Configure Jenkins on Debian 9 – Building Project

Console output:

Install and Configure Jenkins on Debian 9 - Console Output
Install and Configure Jenkins on Debian 9 – Console Output

I recommend you to read Getting Started with Jenkins.

That is All. You have successfully installed Jenkins on CentOS 7 / Ubuntu 16.04 / Debian 9.

POSTS YOU MAY LIKE -:)

Share This Post

Shares