Jenkins is an open source continuous integration tool, which is used for continuous build, continuous deployment and Testing across multiple servers faster. It is a self-contained web-based program, ready to run out-of-the-box, with packages for Windows, Mac OS X and Linux operating systems. It is a Web application build in Java. It performs these tasks automatically when the configurations are added. In this article, I'm providing the guidelines on how to install and configure Jenkins on your Ubuntu 16.04 server.
Pre-requisites
1. A Web Server (Apache/Nginx/Tomcat)
2. Web-Browser
3. Java Platform
Let's start with the installation steps one by one
Install Java
Since, this web application is build on Java platform, the server needs to be installed with the Latest Java Development Kit. I've used this command to install Java on my server.
root@ubuntu:~# apt-get update
root@ubuntu:~# apt-get install default-jdk
You can confirm the Java Version after installing.
root@ubuntu:~# java -version
openjdk version "1.8.0_91"
OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-0ubuntu4~16.04.1-b14)
OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)
Install Apache2
Every Web application requires a Web browser to server the application. I'm using the Apache Webserver to server this purpose. We can install the Apache webserver with this command.
root@ubuntu:~#apt-get install apache2
root@ubuntu:~# apache2 -v
Server version: Apache/2.4.20 (Ubuntu)
Server built: 2016-05-05T15:42:04
root@ubuntu:~#
Installing Jenkins
Before installing Jenkins, we need to add keys and Jenkins packages to the source list.
root@ubuntu:/usr/local/src# sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list'
root@ubuntu:/usr/local/src# cat /etc/apt/sources.list.d/jenkins.list
deb http://pkg.jenkins-ci.org/debian binary/
root@ubuntu:/etc/apt# apt-get install jenkins
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
daemon jenkins
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 68.1 MB of archives.
After this operation, 69.2 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://mirrors.linode.com/ubuntu xenial/universe amd64 daemon amd64 0.6.4-1 [98.2 kB]
10% [Connecting to ftp.icm.edu.pl (2001:6a0:0:31::2)]
10% [Connecting to ftp.icm.edu.pl (2001:6a0:0:31::2)]
10% [Connecting to ftp.icm.edu.pl (2001:6a0:0:31::2)]
Get:2 http://pkg.jenkins-ci.org/debian binary/ jenkins 2.7 [68.0 MB]
Fetched 68.1 MB in 2min 34s (441 kB/s)
Selecting previously unselected package daemon.
(Reading database ... 34869 files and directories currently installed.)
Preparing to unpack .../daemon_0.6.4-1_amd64.deb ...
Unpacking daemon (0.6.4-1) ...
Selecting previously unselected package jenkins.
Preparing to unpack .../archives/jenkins_2.7_all.deb ...
Unpacking jenkins (2.7) ...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for systemd (229-4ubuntu6) ...
Processing triggers for ureadahead (0.100.0-19) ...
Setting up daemon (0.6.4-1) ...
Setting up jenkins (2.7) ...
Processing triggers for systemd (229-4ubuntu6) ...
Processing triggers for ureadahead (0.100.0-19) ..
Start the application after installation
root@ubuntu:/etc/apt# /etc/init.d/jenkins start
[ ok ] Starting jenkins (via systemctl): jenkins.service.
You can manage the Jenkins service using Jenkins daemon. Furthermore, you can analyse the Jenkins log at /var/log/jenkins/jenkins.log for any service troubleshooting.
Confirm the Service Status
root@ubuntu~# netstat -plan | grep java
tcp6 0 0 :::8080 :::* LISTEN 27574/java
tcp6 0 0 :::44507 :::* LISTEN 27574/java
udp6 0 0 :::5353 :::* 27574/java
udp6 0 0 :::33848 :::*
Jenkins runs on the default port 8080. You can modify the Jenkins port 8080 in /etc/default/jenkins file.
root@ubuntu:~# grep HTTP_PORT /etc/default/jenkins
HTTP_PORT=8080
After installing the Jenkins, you can access the Jenkins portal at the URL at http://IP:8080 or http://hostname:8080
Setting up an Apache2 Proxy for port 80 to 8080
We need to configure the virtualhost to proxy port 80 to 8080, so that you can access the Jenkins without specifying any ports, just calling the URL >>>http://IP
Enable Proxy module
You can enable the proxy module by just running this command.
root@jenkins:~# a2enmod proxy
Enabling module proxy.
To activate the new configuration, you need to run:
service apache2 restartroot@jenkins:~# a2enmod proxy_http
Considering dependency proxy for proxy_http:
Module proxy already enabled
Enabling module proxy_http.
To activate the new configuration, you need to run:
service apache2 restart
Restart the Apache service once enabling this module. Now we need to create the virtual host for proxy passing the port. Please see the virtual host details:
root@jenkins:/etc/apache2/sites-available# cat jenkins.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName jenkins.ubuntuserver.com
ServerAlias jenkins
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPreserveHost on
ProxyPass / http://localhost:8080/ nocanon
AllowEncodedSlashes NoDecode
</VirtualHost>root@jenkins:/etc/apache2/sites-enabled# a2ensite jenkins
Enabling site jenkins.
To activate the new configuration, you need to run:
service apache2 reload
By executing this command, you can enable the Jenkins configuration created. That's all :). Access your Jenkins portal by just calling http://IP or http://hostname.
Configure Jenkins
After installing Jenkins, we can access the Jenkins Portal. It will look as the snapshot below:
Now we need to copy and paste this file content from this above location mentioned "/var/lib/jenkins/secrets/initialAdminPassword" and paste in here to continue. This will direct to the next page.
We need to install the suggested Jenkins plugins as per our requirement. Once installed it will ask us to create the Admin user to manage the Jenkins portal. We need to provide these details to continue.
Now it gives us the management Portal.
That's all :). Now we're ready to get started with our continuous integration tool. Thank you for reading this article. I hope you enjoyed reading this. I would recommend your valuable comments and suggestions on this.
The post How to Install Jenkins on Ubuntu 16.04 appeared first on LinOxide.