How to Install Jenkins on CentOS 7 and Configure Git

 Jenkins is free and open source continues integration tool and it’s code is written in Java. It provides the feature of continues build and deployment or in other words we can say it is a automation server. Jenkins are used where continues build and integration is going on for software development.

In this post i will discuss how to install and configure Jenkins on CentOS 7 and RHEL 7.

Prerequisites

  • Deploy a CentOS7 or RHEL 7 Server instance with internet Access 
  • Logged into your machine as a non-root user with sudo privileges.

System requirement

Jenkins requires Java7 or above to function. Java8 is recommended. Jenkins requires a fair amount of memory to operate well. Smaller installations should start around 256MB-1GB.

Step 1 : Update CentOS 7 System 

$ sudo yum -y  update
$ sudo reboot

Step 2 : Install Java 

$ sudo yum list java*
$ sudo yum install java-1.8.0-openjdk.x86_64

After the installation, you can confirm it by running the following command:

$ java -version

This command will tell you about the Java runtime environment that you have installed:

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)

In order to help Java-based applications locate the Java virtual machine properly, you need to set two environment variables: “JAVA_HOME” and “JRE_HOME”.

$ sudo cp /etc/profile /etc/profile_backup
$ echo 'export JAVA_HOME=/usr/lib/jvm/jre-1.8.0-openjdk' | sudo tee -a /etc/profile
$ echo 'export JRE_HOME=/usr/lib/jvm/jre' | sudo tee -a /etc/profile
$ source /etc/profile

Finally, you can print them for review:

echo $JAVA_HOME
echo $JRE_HOME

Step 3 : Install Jenkins 

Use the official YUM repo to install the latest stable version of Jenkins

$ yum -y install wget 

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

In order to allow visitors access to Jenkins, you need to allow inbound traffic on port 8080:

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

firewall-cmd --list-all

Start the Jenkins service and set it to run at boot time:

$ sudo systemctl start jenkins.service

$ sudo systemctl enable jenkins.service

Now, test Jenkins by visiting the following address from your web browser:

http://:8080

You can found the password at /var/lib/jenkins/secrets/initialAdminpassword

Once you enter the password  click on Start using Jenkins Button

Step 4: Install Nginx (optional)

Install Nginx using YUM:

$ sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

$ sudo yum -y install nginx

Modify the configuration of Nginx:

$ sudo vi /etc/nginx/nginx.conf

Find the two lines below:

location / {
}
Insert the six lines below into the { } segment:



location / {
    proxy_pass http://127.0.0.1:8080;
    proxy_redirect off;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
}

Start and enable the Nginx service:

$ sudo systemctl start nginx.service
$ sudo systemctl enable nginx.service

Finally, visit the following address from your web browser to confirm your installation:

http://

Step 5 : Configure GitHub project using git plugin in Jenkins.

Let’s Assume I have a ‘workspace’ project on GitHub and wants to integrate this project in Jenkins using git plugin.

Let’s first install git package on your machine on which you have installed Jenkins because Jenkins use git command to pull the GitHub project code.

$ sudo yum -y install git 

Login to the GitHub and get the Web URL of your project.

Login to the Jenkins portal, Click on “New Item”

Select the Freestyle Project and Specify the name as per your setup. Here its ‘Workshop_proj

Specify the Project Description and Select Git option in Source Code Management Tab and specify the Web URL of your GitHub Project and its credentials. In the Build Tab select the option that suits your setup and then finally click on Apply.

In the Next step click on the “Build Now” option from Jenkins Dashboard to pull the GitHub Project Code.

Click on the Workspace Option to view Code or files of GitHub Project. Whenever a new code is pushed on the GitHub project it will be automatically push to Jenkins workspace with new versions.

we can also view the project workspace from terminal as well.

Video Tutorial : 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Powered by WordPress.com.

Up ↑

%d bloggers like this: