Jenkins on CentOS
13 October 2015
Jenkins is an opensource and probably the most popular continuous integration tool in the Java community. There are many plugins out there available to make your coding life easier. It supports almost all version control systems and can run all your Maven or Ant tasks.
To install and configure Jenkins on CentOS, we have to first make sure that Java is installed on your machine. If not, please refer to this post from if-not-true-then-false.com
Add Jenkins to your repository
$ sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
Resolving pkg.jenkins-ci.org (pkg.jenkins-ci.org)... 199.193.196.24
Connecting to pkg.jenkins-ci.org (pkg.jenkins-ci.org)|199.193.196.24|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 75 [text/plain]
Saving to: ‘/etc/yum.repos.d/jenkins.repo’
$ sudo rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key
Install jenkins
$ sudo yum install jenkins
Resolving Dependencies
--> Running transaction check
---> Package jenkins.noarch 0:1.586-1.1 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
jenkins noarch 1.586-1.1 jenkins 59 M
Transaction Summary
================================================================================
Install 1 Package
Total download size: 59 M
Installed size: 65 M
Is this ok [y/d/N]: y
Downloading packages:
jenkins-1.586-1.1.noarch.rpm | 59 MB 00:34
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
Installing : jenkins-1.586-1.1.noarch 1/1
Verifying : jenkins-1.586-1.1.noarch 1/1
Installed:
jenkins.noarch 0:1.586-1.1
Complete!
To start jenkins on boot
$ sudo chkconfig jenkins on
$ sudo systemctl start jenkins
$ sudo netstat -tnlp | grep 8080
tcp6 0 0 :::8080 :::* LISTEN
To change jenkins default port
To change jenkins default port, you need to edit /etc/sysconfig/jenkins
and look for JENKINS_PORT=8080. Change 8080 into your desired port number. Make sure it is available and not taken by any other application such as Tomcat.
## Type: integer(0:65535)
## Default: 8080
## ServiceRestart: jenkins
#
# Port Jenkins is listening on.
# Set to -1 to disable
#
JENKINS_PORT="8081"
Proxying jenkins
To proxy jenkins using httpd, you will need a URL prefix to replace its existing web root context (/). To do this, edit /etc/sysconfig/jenkins
and look for JENKINS_ARGS then add --prefix=/jenkins
## Type: string
## Default: ""
## ServiceRestart: jenkins
#
# Pass arbitrary arguments to Jenkins.
# Full option list: java -jar jenkins.war --help
#
JENKINS_ARGS="--prefix=/jenkins"
Under /etc/httpd/conf.d
create a file called jenkins.conf
and type this contents
<VirtualHost *:80>
ServerName centos7
ProxyRequests Off
ProxyPreserveHost On
<Proxy http://localhost:8081/*>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /jenkins http://localhost:8081/jenkins
ProxyPassReverse /jenkins http://localhost:8081/jenkins
</VirtualHost>
Restart jenkins and httpd. After which, jenkins should be available on http://centos7/jenkins
$ sudo systemctl restart httpd
$ sudo systemctl restart jenkins