How to Install Jenkins Automation Server with Apache on Ubuntu 16.04
Jenkins is an automation server forked from the Hudson project. Jenkins is a server based application running in a Java servlet container, it has support for many SCM (Source Control Management) software systems including Git, SVN, and Mercurial. Jenkins provides hundreds of plugins to automate your project. Jenkins created by Kohsuke Kawaguchi, first released in 2011 under MIT License, and it’s free software.eval(ez_write_tag([[728,90],’howtoforge_com-box-3′,’ezslot_6′,106,’0′,’0′]));
In this tutorial, I will show you how to install the latest Jenkins version on Ubuntu Server 16.04. We will run Jenkins on our own domain name, and we will to install and configure Jenkins to run under the apache web server with the reverse proxy for Jenkins.eval(ez_write_tag([[580,400],’howtoforge_com-medrectangle-3′,’ezslot_2′,121,’0′,’0′]));
- Ubuntu Server 16.04 – 64bit
- Root Privileges
Step 1 – Install Java OpenJDK 7
Jenkins is based on Java, so we need to install Java OpenJDK version 7 on the server. In this step, we will install Java 7 from a PPA repository which we will add first.
By default, Ubuntu 16.04 ships without the python-software-properties package for managing PPA repositories, so we must install this package first. Install python-software-properties with apt command.
apt-get install python-software-properties
Next, add Java PPA repository to the server.
Just Press ENTER
Update the Ubuntu repository and install the Java OpenJDK with apt command.
apt-get install openjdk-7-jdk
Verify the installation by typing the command below:
and you will get the Java version that is installed on the server.eval(ez_write_tag([[580,400],’howtoforge_com-medrectangle-4′,’ezslot_1′,108,’0′,’0′]));
Step 2 – Install Jenkins
Jenkins provides an Ubuntu repository for the installation packages and we will install Jenkins from this repository.
Add Jenkins key and repository to the system with the command below.
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
echo 'deb https://pkg.jenkins.io/debian-stable binary/' | tee -a /etc/apt/sources.list
Update the repository and install Jenkins.
apt-get install jenkins
When the installation is done, start Jenkins with this systemctl command.
systemctl start jenkins
Verify that Jenkins is running by checking the default port used by Jenkins (port 8080). I will check it with the netstat command below:
Jenkins is installed and running on port 8080.
Step 3 – Install and Configure Apache as Reverse Proxy for Jenkins
In this tutorial we will run Jenkins behind an apache web server, we will configure apache as the reverse proxy for Jenkins. First I will install apache and enable some require modules, and then I’ll create the virtual host file with domain name my.jenkins.id for Jenkins. Please use your own domain name here and replace it in all config files wherever it appears.
Install apache2 web server from Ubuntu repository.
apt-get install apache2
When the installation is done, enable the proxy and proxy_http modules so we can configure apache as frontend server/reverse proxy for Jenkins.
Next, create a new virtual host file in the sites-available directory.
Paste virtual host configuration below.
Allow from all
ProxyPass / http://localhost:8080/ nocanon
ProxyPassReverse / http://localhost:8080/
ProxyPassReverse / http://my.jenkins.id/
Save the file. Then activate the Jenkins virtual host with the a2ensite command.
Restart Apache and Jenkins.
systemctl restart apache2
systemctl restart jenkins
Check that port 80 and 8000 are in use by Jenkins and Apache.
Step 4 – Configure Jenkins
Jenkins is running on the domain name ‘my.jenkins.id’. Open your web browser and type in the URL. You will get the screen that requests you to enter the initial admin password. A password has been generated by Jenkins already, so we just need to show and copy the results to the password box.
Show initial admin password Jenkins with cat command.
Paste the results to the screen and click ‘Continue‘.
Now we should install some plugins in Jenkins to get a good foundation for later use. Choose ‘Install Suggested Plugins‘, click on it.
Jenkins plugins installations in progress.
After plugin installation, we have to create a new admin password. Type in your admin username, password, email etc. and click on ‘Save and Finish‘.
Click start and start using Jenkins. You will be redirected to the Jenkins admin dashboard.
Jenkins installation and Configuration finished successfully
Step 5 – Jenkins Security
From the Jenkins admin dashboard, we need to configure the standard security settings for Jenkins, click on ‘Manage Jenkins‘ and then ‘Configure Global Security‘.
Jenkins provides several authorization methods in the ‘Access Control‘ section. I select ‘Matrix-based Security‘ to be able to control all user privileges. Enable the admin user at the box ‘User/Group‘ and click add. Give the admin all privileges by checking all options, and give the anonymous just read permissions. Now Click ‘Save‘.
You will be redirected to the dashboard, and if there is login option, just type your admin user and password.
Step 6 – Testing a simple automation job
In this section, I just want to test a simple job for the Jenkins server. I will create a simple job for testing Jenkins and to find out the server load with the top command.
From the Jenkins admin dashboard, click ‘Create New Job‘.
Enter the job name, I’ll use ‘Checking System’ here, select ‘Freestyle Project‘ and click ‘OK‘.
Go to the ‘Build‘ tab. On the ‘Add build step‘, select the option ‘Execute shell‘.
Type in the command below into the box.
top -b -n 1 | head -n 5
Now you are on the job page of the job ‘Project checking system’. Click ‘Build Now‘ to execute the job ‘checking system’.
After the job has been executed, you will see the ‘Build History‘, click on the first job to see the results.
Here are the results from the job executed by Jenkins.
Jenkins installation with Apache web server on Ubuntu 16.04 completed successfully.