How to install and Configure Jenkins on CentOS 7 and RHEL 7

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.

Step:1 Add Jenkins Repository

Jenkins package is not available in the default CentOS and RHEL repositories. So we need to add jenkins repository using the beneath commands.

[[email protected] ~]# wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins.io/redhat-stable/jenkins.repo
[[email protected] ~]# rpm --import http://pkg.jenkins.io/redhat-stable/jenkins.io.key

Step:2 Install Jenkins and Java

Run the below  yum command to install Jenkins and java.

[[email protected] ~]# yum install jenkins java-1.8.0-openjdk –y

Step:3 Start and Enable Jenkins Service

Run the following systemctl commands to start and enable the jenkins service

[[email protected] ~]# systemctl start jenkins
[[email protected] ~]# systemctl enable jenkins

Step:4 Open the ports (80 and 8080) in OS firewall.

In case firewall is enabled on your Linux server then run the following commands to open jenkins related ports like 80 and 8080.

[[email protected] ~]# firewall-cmd --zone=public --add-port=8080/tcp --permanent
success
[[email protected] ~]# firewall-cmd --zone=public --add-service=http --permanent
success
[[email protected] ~]# firewall-cmd --reload
success
[[email protected] ~]#
Step:5 Access the Jenkins Web portal

Access the URL : http://<Ip-Address-of-your-Server>:8080

Jenkins-administrator-password-centos7

Admin password is created and stored in the log file  “/var/log/jenkins/jenkins.log“. Run the below command to get the password.

[[email protected] ~]# grep -A 5 password /var/log/jenkins/jenkins.log

Copy the password and paste it in above windows and click on Continue..

In the next windows Select the option : Install suggested plugins

SetupWizard-Jenkins-Centos7

SetupWizard-Jenkins-plugin-installation

As we can see required plugin installation is in progress for Jenkins. Once it is done with plugin installation. It will ask to create Admin User

Admin-User-Jenkins-Portal-Centos7

Click on Save and Finish

Jenkins-Installation-Completed-Message

click on “Start using Jenkins

Jenkins-Dashboard-Centos7

Now Configure GitHub project using git plugin in Jenkins.

Let’s Assume I have a ‘cloudtechi’ 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.

[[email protected] ~]# yum install git

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

Github-Project-Web-URL

Login to the Jenkins portal, Click on “New Item

Select the Freestyle Project and Specify the name as per your setup, In my case I putting as “techi_project

NewItem-Name-Jenkins-Dashboard-Centos7

Click on OK

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.

GitHub-Project-Credentials-Jenkins-Centos7

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

Build-GitHub-ProjectCode-Jenkins

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.

Workspace-GitHub-Project-Jenkins

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

[[email protected] ~]# cd /var/lib/jenkins/workspace/techi_project/
[[email protected] techi_project]# ls -l
total 12
-rw-r--r--. 1 jenkins jenkins 63 Aug  7 03:23 cloudstack
-rw-r--r--. 1 jenkins jenkins 13 Aug  7 03:23 README.md
-rw-r--r--. 1 jenkins jenkins 84 Aug  7 03:23 testing.md
[[email protected] techi_project]#

We can this code to deploy on other machines as well. That’s all, Basic Jenkins installation and configuration is completed 🙂

8 Responses

  1. Mohanish Mahajan says:

    hi,

    I used RHEL7 and followed above commands. However the server is not listening on 8080. I tried to do a telnet from localhost but it says connection refused.
    Please if any help.
    Also no log file getting generated under /etc/var/log/jenkins

  2. nafish shahzad says:

    check whether it is used by another process or not
    netstat -anp |grep 8080

    • Siddhesh_Khedekar says:

      I have same issue as Mohanish. Tried Suggestions from Pradeep and Mohanish but no success.
      Any suggestions? I am working on Virtual box Centos7 image.

  3. Vineeth says:

    Very nice explanation!

  4. Siddhesh_Khedekar says:

    Hi
    I am facing same issue as Mohanish.
    When I do : netstat -anp |grep 8080 , No output is coming.
    However when I do : sudo service jenkins status, below output is coming –
    jenkins.service – LSB: Jenkins Automation Server
    Loaded: loaded (/etc/rc.d/init.d/jenkins; bad; vendor preset: disabled)
    Active: active (exited) since Thu 2018-08-23 11:39:01 EDT; 1h 22min ago
    Docs: man:systemd-sysv-generator(8)

    Aug 23 11:39:00 l-156063904.wipro.com systemd[1]: Starting LSB: Jenkins Automation Server…
    Aug 23 11:39:00 l-156063904.wipro.com runuser[1643]: pam_unix(runuser:session): session op…0)
    Aug 23 11:39:01 l-156063904.wipro.com jenkins[1638]: Starting Jenkins Jenkins requires Jav…re
    Aug 23 11:39:01 l-156063904.wipro.com jenkins[1638]: java.lang.UnsupportedClassVersionErro….0
    Aug 23 11:39:01 l-156063904.wipro.com jenkins[1638]: at Main.main(Main.java:128)
    Aug 23 11:39:01 l-156063904.wipro.com jenkins[1638]: [ OK ]
    Aug 23 11:39:01 l-156063904.wipro.com systemd[1]: Started LSB: Jenkins Automation Server.

    Any suggestions?

  5. Franck Gros-Dubois says:

    hi, the best way to know which port Jenkins is running is to read the jenkins.service
    If you install Jenkins by yourself, by downloading the war, you need to write it yourself.
    If you use the yum install, then you need to find that file.
    A find | grep should help you. you need to find this line :

    path_to_your_java/java -jar path_to_jenkins.war/jenkins.war –httpPort=your_port

    With a yum install this line will be with variables. You need to track it.
    Then, you’ll know what is your port for Jenkins.

    Regards,

  6. Andy says:

    Hey my friend,

    Excellent article – really helped me.

    One very minor thing, “Jenkins is free and open source continues integration tool…”, that continues ought to be continuous.

    Thanks again.

Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest