Install Jenkins on Centos7
Overview

Jenkins is a self-contained, open source automation server which can be used to automate all sorts of tasks related to building, testing, and delivering or deploying software.
Jenkins can be installed through native system packages, Docker, or even run standalone by any machine with a Java Runtime Environment (JRE) installed (Jenkins.io).
Prerequisites
- Vagrant, see how to install Vagrant here
- Add the following host entries on local device
/etc/hosts:1 2192.168.0.1 jenkins.local 192.168.1.1 agent.local
Startup Vagrant
Create Vagrantfile and fill the following code.
| |
And start vagrant by typing vagrant up on your terminal.
Install Jenkins
SSH into jenkins machine, you can use vagrant ssh jenkins or ssh from host ssh -p 2230 vagrant@jenkins.local -i .vagrant/machines/jenkins/virtualbox/private_key
Login as root sudo su -
Install wget yum install -y wget
Create jenkins limit file /etc/security/limits.d/30-jenkins.conf
| |
Setup firewall
| |
We should get an outuput
| |
Add the following entries to /etc/hosts
| |
Add AdoptOpenJDK repository
| |
Add repository to get latest Git
| |
Add jenkins repository
| |
Create directory
| |
Uninstall old Git by typing yum remove git* on your terminal
Install AdoptOpenJDK, Git, Jenkins and Fontconfig
| |
Edit the /etc/sysconfig/jenkins file
| |
Change owner jenkins config file chown -R jenkins:jenkins /var/cache/jenkins
Start jenkins by typing systemctl start jenkins and get status systemctl -l status jenkins
We should get an output status.
| |
Setup Jenkins UI
Access http://jenkins.local:8080 on your host and should be like below.

Type sudo cat /var/lib/jenkins/secrets/initialAdminPassword to get password and paste it on field then continue.
Install suggested plugin

Create first admin user.

Setup jenkins url and click start using jenkins.

And restart jenkins then login with admin user http://jenkins.local:8080/restart
Agent Installation
SSH into jenkins machine, you can use vagrant ssh agent or ssh from host ssh -p 2231 vagrant@agent.local -i .vagrant/machines/agent/virtualbox/private_key
Login as root sudo su -
Setup firewall
| |
We should get an outuput
| |
Add the following entries to /etc/hosts
| |
Add AdoptOpenJDK repository
| |
Add repository to get latest Git
| |
Uninstall old Git by typing yum remove git* on your terminal
Install AdoptOpenJDK, Git, Fontconfig and Wget
| |
Install docker and unzip from Install Docker Engine on CentOS
- Remove old docker if any
yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine yum -y install yum-utilsyum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repoyum -y install docker-ce docker-ce-cli containerd.io unzipsystemctl enable dockersystemctl start dockergroupadd dockersystemctl -l status dockerexitsudo usermod -aG docker $USERexit
SSH again to vagrant agent
| |
Try running container by typing docker run hello-world on your terminal.
Installing maven
sudo su -mkdir -p /opt/tools/mavencd /opt/tools/mavenwget https://downloads.apache.org/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gztar zxvf apache-maven-3.6.3-bin.tar.gzrm -f apache-maven-3.6.3-bin.tar.gzln -s apache-maven-3.6.3 latest
Installing gradle
mkdir -p /opt/tools/gradlecd /opt/tools/gradlewget https://services.gradle.org/distributions/gradle-7.1.1-bin.zipunzip gradle-7.1.1-bin.ziprm -f gradle-7.1.1-bin.zipln -s gradle-7.1.1 latest
Export maven and gradle to profile
echo "PATH=/opt/tools/gradle/latest/bin:\$PATH" > /etc/profile.d/gradle.shecho "PATH=/opt/tools/maven/latest/bin:\$PATH" > /etc/profile.d/maven.shchown -R vagrant:vagrant /opt/toolsexitexit
Verify that maven and gradle has already installed on your machine.
ssh -p 2231 vagrant@agent.local -i .vagrant/machines/agent/virtualbox/private_keymvn --versiongradle --version
Connect Agent to Jenkins
Manage jenkins at system configuration.

And fill field like below

Add nodes and fill like below


Add credential

Click advanced and set port to 2231 then click save.

Create Test Job (Pipeline)
Create new pipeline then save

Create build script to running jobs.
| |
You can see my example on Github
References
Jenkins.io - Jenkins User Documentation
CloudBeesTV - How To Install Jenkins on CentOS 7
RedHat - Continuous Delivery to JBoss EAP and OpenShift with the CloudBees Jenkins Platform
CloudBees - Prepare Jenkins for Support
Jenkins - Jenkins Redhat Packages
Docker - Install Docker Engine on CentOS
Docker - Post-installation steps for Linux
AdoptOpenJDK - Installation