Latest

Tuesday, 8 January 2019

How to Install Jenkins 2 on CentOS / RHEL 7

Installing Jenkins 2 on CentOS / RHEL 7

Jenkins is a Java-based, open-source automation server. Jenkins is used to automate all sorts of tasks related to building, testing and delivering or deploying software. Jenkins is a fork of Project Hudson and it is maintained by the original Husdon developers since the Hudson had been acquired by Oracle. However, Jenkins has been evolved very much since its inception from Hudson.

In DevOps, this automated process of building, testing and delivering is called CI/CD (Continuous Integration / Continuous Delivery) pipeline.

CI (Continuous integration) is a practice in which team members regularly commits their code changes to the version control repository (such as git or svn), after which automated builds and tests are performed using build tools (such as Apache Ant, Apache Maven, Gradle, Junit, etc).

CD (Continuous delivery) is a series of practices where code changes are automatically built, tested and deployed to production.

In this article, we will install Jenkins 2 on CentOS 7 server. Although the same steps can be used to install Jenkins on Red Hat Enterprise Linux (RHEL) 7.

Installing Jenkins 2 on CentOS / RHEL 7

Table of Contents:

 

System Specification:

We have provisioned a CentOS 7 virtual machine with following specification:

  • Hostname - jenkins-01.recipes.com
  • IP Address - 192.168.116.130/24
  • Operating System - CentOS 7.6

 

Install OpenJDK 8 on CentOS 7:

Since, Jenkins is a Java application therefore it requires JVM (Java Virtual Machine) to execute. Jenkins 2 is the current major version and it requires Java 8.

Connect to jenkins-01.recipes.com using ssh and install OpenJDK from CentOS 7 yum repository.

# yum install -y java-1.8.0-openjdk-devel

yum has installed OpenJDK and its dependent packages.

Java executables has been automatically added to PATH environment variable. Therefore, we are only required to set the JAVA_HOME environment variable.

# echo "export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64" >> /etc/profile
# . /etc/profile
# env | grep JAVA_HOME
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64

Verify Java version.

# java -version
openjdk version "1.8.0_191"
OpenJDK Runtime Environment (build 1.8.0_191-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)

OpenJDK has been installed and configured successfully.

 

Install Jenkins 2 on CentOS 7:

Jenkins is available to install in various forms.

  • Individual RPM:
    Individual RPMs are available for every version of Jenkins, but one has to resolve dependencies manually.
  • Jenkins yum Repository:
    A Yum repository is provided for Jenkins packages. Here, dependent packages will be installed automatically.
  • Generic Web Archive:
    This Java web archive requires to be executed either using java command or should be deployed on a Jave EE Server (e.g Apache Tomcat) to work.

We will use Jenkins yum repository, because, it is quite simple to understand and in this method dependencies will resolved automatically.

Jenkins can be downloaded from Jenkins official website. Jenkins website also provides commands to install jenkins yum repository on CentOS 7.

Install jenkins yum repository using the following commands.

# wget https://pkg.jenkins.io/redhat-stable/jenkins.repo -O /etc/yum.repos.d/jenkins.repo
--2019-01-08 00:14:26--  https://pkg.jenkins.io/redhat-stable/jenkins.repo
Resolving pkg.jenkins.io (pkg.jenkins.io)... 52.202.51.185
Connecting to pkg.jenkins.io (pkg.jenkins.io)|52.202.51.185|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 85
Saving to: â/etc/yum.repos.d/jenkins.repoâ

100%[======================================>] 85          --.-K/s   in 0s

2019-01-08 00:14:27 (5.48 MB/s) - â/etc/yum.repos.d/jenkins.repoâ saved [85/85]

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

Build yum cache for faster access to repositories.

# yum makecache
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.ges.net.pk
 * extras: mirrors.ges.net.pk
 * updates: mirrors.ges.net.pk
base                                                     | 3.6 kB     00:00
extras                                                   | 3.4 kB     00:00
jenkins                                                  | 2.9 kB     00:00
updates                                                  | 3.4 kB     00:00
Metadata Cache Created

Install Jenkins using yum command.

# yum install -y jenkins

Start and enable jenkins service.

# systemctl start jenkins
# systemctl enable jenkins
jenkins.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig jenkins on

Allow Service Port 8080/tcp in Linux Firewall.

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

Browse URL http://jenkins-01.recipes.com:8080/jenkins using a client browser.

jenkins-sign-in-01

Obtain the autogenerated password from the given file.

# cat /var/lib/jenkins/secrets/initialAdminPassword
1f6a106d9af642909ad0ecc5abd8afec

Unlock Jenkins using this password.

jenkins-sign-in-02

Click on continue.

jenkins-setup-wizard-01

Click on Install Suggested Services.

jenkins-setup-wizard-02

Jenkins will install most commonly used plugins such as Apache Ant, Gradle, Git, etc.

jenkins-setup-wizard-03

Create an Admin user here.

Click on Save and Continue.

jenkins-setup-wizard-04

Jenkins provide a root URL here for accessing its various resources.

If you are happy with it then click on Save and Finish.

jenkins-setup-wizard-05

Jenkins has been successfully configured.

Click on Start using Jenkins.

jenkins-startup-01jenkins-sign-in-03

Login using the admin user ahmer that we have created with Jenkins Setup Wizard.

jenkins-dashboard-01

Installation of Jenkins 2 on CentOS 7 has been completed.

You can refer to Jenkins User Documentation to understand the workflow and getting start with Jenkins.

If you find this article useful? Don't you mind support us by Buy Me A Coffee


No comments:

Post a Comment

© 2022 CentLinux. All Rights Reserved.