Install Jenkins on Amazon EC2 (Ubuntu Server 14.04 LTS)

Jenkins is a powerful application that allows continuous integration and helps in the continuous delivery of projects, regardless of the platform you are working on. It is an open source tool that can handle any kind of build or continuous integration. You can integrate Jenkins with a number of testing and deployment technologies. In this post, we will explain how you can install Jenkins on an Amazon EC2 (Ubuntu Server 14.04 LTS) Instance.

Assuming that you have already completed the below three steps. If not then you can follow our below posts to complete these prerequisites.

  1. First, create a new Amazon EC2 Instance(Ubuntu Server 14.04 LTS) and setup Security Groups and open up ports 22, 80 and 443.  See Blog: Create a new Instance (Ubuntu 14.04) on AWS EC2 and setup Security Groups
  2. Then connect to your EC2 Instance via SSH. See Blog: Connect to AWS EC2 Instance via Putty/SSH
  3. For Jenkins first, you have Install Java on your Instance.  See Blog: Install OpenJDK 8 on Ubuntu 14.04 LTS

Step 1: Fixing Locales in Ubuntu 14.04 LTS on Amazon EC2

Once, we run the above command you should be able to see the below message on the command interface.

Install Jenkins on Amazon EC2 (Ubuntu Server 14.04 LTS)1

Step 2: The Installation

Now, we’re going to add the repository for the Jenkins package. So, we need to install the public key for the Jenkins repository to tell Ubuntu that this is a trusted repository:

Once, we run the above command you should be able to see the below message on the command interface.

Install Jenkins on Amazon EC2 (Ubuntu Server 14.04 LTS)2

Then, we need to tell Ubuntu where the package repository is. We just add the package repository to the list of repositories:

Once, we run the above command you should be able to see the below message on the command interface.

Install Jenkins on Amazon EC2 (Ubuntu Server 14.04 LTS)3

The best practice is to Update packages first:

Once, we run the above command you should be able to see the below message on the command interface.

Install Jenkins on Amazon EC2 (Ubuntu Server 14.04 LTS)4

Finally, we install Jenkins:

Once, we run the above command you should be able to see the below message on the command interface.

Install Jenkins on Amazon EC2 (Ubuntu Server 14.04 LTS)5

Step 3: Verify Installation

Once, we run the above command you should be able to see the below message on the command interface.

Install Jenkins on Amazon EC2 (Ubuntu Server 14.04 LTS)6

This verifies that Jenkins service has been installed is actually running on httpPort=8080.

The reason for that is that Jenkins package actually created a user called Jenkins on the system that allows Jenkins to be run as an unprivileged user.

We don’t want to run it as a root user for security reasons. Now the unprivileged user can’t start the server on privilege port like HTTP port 80 so, it runs on 8080, on the other hand, we don’t have to specify the port 8080 every time to connect to Jenkins server from a web browser.

So, for what we are going to do is to setup an apache server to send proxy requests from port 80 to our Jenkins server port 8080 for that we have to install and configure Apache web server.

Now, to install and configure Apache Web Server we need to follow the below steps.

Step 4: Installing and Configuring Apache

Install apache2 server

Once, we run the above command you should be able to see the below message on the command interface.

Install Jenkins on Amazon EC2 (Ubuntu Server 14.04 LTS)7

Next command is to enable module proxy

Once, we run the above command you should be able to see the below message on the command interface.

Install Jenkins on Amazon EC2 (Ubuntu Server 14.04 LTS)8

After the above, we need to run the next command to enable module proxy_http

Once, we run the above command you should be able to see the below message on the command interface.

Install Jenkins on Amazon EC2 (Ubuntu Server 14.04 LTS)9

Now configure Apache to proxy the request from port 80 to 8080 to Jenkins server for that you have to paste below configuration in the file. Don’t forget to change your EC2 hostname.

For open ‘jenkins.conf’ file type below command and paste above configuration *Don’t forget to change your EC2 hostname*

Once, we run the above command you should be able to see the below message on the command interface.

Install Jenkins on Amazon EC2 (Ubuntu Server 14.04 LTS)10

Step 5: Enabling jenkins.conf

Once the installation is complete we move on to the configuration of the files.We need to enable our new site that we’ve set up in Apache and reload the apache2 service.

Once, we run the above command you should be able to see the below message on the command interface.

Install Jenkins on Amazon EC2 (Ubuntu Server 14.04 LTS)11

Next command is to restart Apache service

Once, we run the above command you should be able to see the below message on the command interface.

Install Jenkins on Amazon EC2 (Ubuntu Server 14.04 LTS)12

Step 6 : Unlock Jenkins

Access the Jenkins server by web browser then you will see below screen which means you have configured Jenkins properly.

Install Jenkins on Amazon EC2 (Ubuntu Server 14.04 LTS)13

Then the next step is to unlock your Jenkins, for that we need to copy the administrator password from “/var/lib/jenkins/secrets/initialAdminPassword” file we could do that by executing the below command on your EC2 server to copy the password and unlock your Jenkins.

Then you will see the Jenkins dashboard.

Install Jenkins on Amazon EC2 (Ubuntu Server 14.04 LTS)14

You may also like