Jenkins is an open-source Continuous Integration and Continuous Deployment tool. It is an automation tool that helps build, test and deploy software reliably. It is written in Java and comes with hundreds of plugins. Jenkins also supports the distribution of work across multiple servers. It is very easy to configure Jenkins and get started with it. In this article, we will install Jenkins using the .war file in Apache Tomcat. We will use AWS EC2 Ubuntu 18.04 server to perform this activity. You can even use a Virtual Machine on your local machine or remote server with Ubuntu 18.04 on it.

Pre-requisites

  1. AWS Account (Create if you don’t have one).
  2. An EC2 Instance(Click here to learn to create an EC2 Instance) or a VM with at least 256 MB of RAM and 1 GB of drive space.

What will we do?

  1. Download Jenkins and Apache Tomcat Package.
  2. Install Java and initialize Apache Tomcat with Jenkins.
  3. Initial Setup of Jenkins.

Download Jenkins and Apache Tomcat Package

Before we get started with the installation, let’s check the OS version and see if Java is available on the server using the following commands.

cat /etc/issue

java

How to install Jenkins using a .war file on AWS EC2 Ubuntu 20.04 instance ubuntu

Check the current user you are logged in with and change to “root” user.

whoami

sudo -i

whoami

Create a  new directory in /opt/ where we will download Jenkins and Apache Tomcat packages.

cd /opt/

mkdir jenkins

cd jenkins/

pwd

How to install Jenkins using a .war file on AWS EC2 Ubuntu 20.04 instance ubuntu

Go to Jenkins download page and get the URL of the war file to download the Jenkins package

https://www.jenkins.io/download/

In this case, the following is the URL to download the war file of Jenkins.

https://get.jenkins.io/war-stable/2.263.4/jenkins.war

How to install Jenkins using a .war file on AWS EC2 Ubuntu 20.04 instance ubuntu

Now, you can use the “wget” command to download the war file on your server.

wget https://get.jenkins.io/war-stable/2.263.4/jenkins.war

ls -l

How to install Jenkins using a .war file on AWS EC2 Ubuntu 20.04 instance ubuntu

Go to the Apache tomcat website to download the package. We will use Apache Tomcat 9 package.

https://tomcat.apache.org/download-90.cgi

How to install Jenkins using a .war file on AWS EC2 Ubuntu 20.04 instance ubuntu

Get the URL of the package and download it on the server using “get”. 

wget https://downloads.apache.org/tomcat/tomcat-9/v9.0.43/bin/apache-tomcat-9.0.43.tar.gz

ls -lt

How to install Jenkins using a .war file on AWS EC2 Ubuntu 20.04 instance ubuntu

Install Java and initialize Apache Tomcat with Jenkins

Apache Tomcat requires Java to run, so before we proceed we need to install java on the server.

Use the following command to update the system.

apt update

Once the system is updated, install Java 8 on Ubuntu using the following command.

apt install openjdk-8-jdk

How to install Jenkins using a .war file on AWS EC2 Ubuntu 20.04 instance ubuntu

Check the java version to make sure that the Java has been installed.

java -version

ls -lt

How to install Jenkins using a .war file on AWS EC2 Ubuntu 20.04 instance ubuntu

Now, we are ready to use Apache Tomcat. Extract the tar file we have downloaded in the previous step.

tar -zxvf apache-tomcat-9.0.43.tar.gz

ls -lt

How to install Jenkins using a .war file on AWS EC2 Ubuntu 20.04 instance ubuntu

Move/Copy Jenkins war file to webapp directory of Apache Tomcat.

mv jenkins.war apache-tomcat-9.0.43/webapps/

ls -lt

ls -lt apache-tomcat-9.0.43/webapps/

How to install Jenkins using a .war file on AWS EC2 Ubuntu 20.04 instance ubuntu

We are now ready to start Apache Tomcat. Before that, let’s see if 8080 used by Apache Tomcat is free or not.

cd apache-tomcat-9.0.43/bin/

netstat -tulpn | grep 8080

If no other service is running on 8080, we are ready to start Apache Tomcat. 

Use the following command to start the service.

./startup.sh

Check if the service has started.

netstat -tulpn | grep 8080

How to install Jenkins using a .war file on AWS EC2 Ubuntu 20.04 instance ubuntu

Verify that the Apache Tomcat has started successfully and there are no errors in logs.

tail -100f ../logs/catalina.out

How to install Jenkins using a .war file on AWS EC2 Ubuntu 20.04 instance ubuntu

We need to do the initial setup of Jenkins, to do so we need to use the password available in “initialAdminPassword”. 

Get the password that will be required to login into Jenkins. You can see the “initialAdminPassword” file path in the Apache Tomcat logs.

cat  /root/.jenkins/secrets/initialAdminPassword

You can also check if the Apache Process is running, use the following command.

ps -ef| grep apache

How to install Jenkins using a .war file on AWS EC2 Ubuntu 20.04 instance ubuntu

To access Jenkins on Port 8080, we need to make sure that the incoming connection on the port is allowed in the Security group of the EC2 instance.

How to install Jenkins using a .war file on AWS EC2 Ubuntu 20.04 instance ubuntu

Get the public IP of the EC2 instance.

How to install Jenkins using a .war file on AWS EC2 Ubuntu 20.04 instance ubuntu

Initial Setup of Jenkins

Access Jenkins on http://:port/jenkins 

http://52.87.233.129:8080/jenkins

Insert the password fetched from the “initialAdminPassword” file.

How to install Jenkins using a .war file on AWS EC2 Ubuntu 20.04 instance ubuntu

Customize Jenkins and install suggested plugins. This will take some time.

How to install Jenkins using a .war file on AWS EC2 Ubuntu 20.04 instance ubuntu

You can create a new Admin user or skip the user creation and proceed with the current Admin user and Password. 

How to install Jenkins using a .war file on AWS EC2 Ubuntu 20.04 instance ubuntu

Keep the URL as is and click on “Save and Finish”.

How to install Jenkins using a .war file on AWS EC2 Ubuntu 20.04 instance ubuntu

Now Jenkins is ready to use.

How to install Jenkins using a .war file on AWS EC2 Ubuntu 20.04 instance ubuntu

Here you see the Jenkins Dashboard.

How to install Jenkins using a .war file on AWS EC2 Ubuntu 20.04 instance ubuntu

Conclusion

In this article, we saw the steps to install Jenkins using the .war file. We carried out this activity on the AWS EC2 Ubuntu 18.04 Server. We installed Java which is required by Jenkins and used Apache Tomcat to deploy the jenkins.war file. We logged in using the Admin user and did the initial setup of Jenkins using the suggested plugins.