How to install Jenkins on EC2 instance [Step-by-Step]

In this article, we will learn how we can install Jenkins on AWS instance. Continuous integration and Continuous deployment has become the very need of all the organizations over the world for shipping software efficiently and quickly. One of the best CI/CD tool available in the market today is Jenkins that is widely needed and accepted over many organizations for their CI/CD purposes.

 

Overview on Jenkins

Jenkins is an open source server written in java which is crucially used for continuous integration and continuous deployment in software development life cycle. This CI server mainly runs on Apache Tomcat. Jenkins is more functionality driven than UI driven and automates the process related to build, test and deployment. This makes the CI/CD process for the developers very easy and they can concentrate more on the new features and seamlessly integrate them into their Jenkins pipelines.

Advertisement

 

Overview on EC2 Instance

Amazon Elastic Compute Cloud (EC2) is an AWS web service that provides computing power to businesses all over the world. Aws web interface gives complete control of the resources and lets user to choose their own operating system, number of CPU's , storage and memory. Aws Ec2 also reduces the booting time to minutes and new instances can be easily scaled up and scaled down as the requirements change. EC2 with it's security groups and network ACL's also provides security features for the computing resources we deploy.

 

Features of Jenkins

The features of Jenkins cant be said as a one or two , there are so many that cant be listed but I am listing a few down for you people:

  • Easy Installation and Configuration : Jenkins can be very easily installed on different operating systems like Linux , Windows , Mac and be easily setup due to it's amazing web interface. Jenkins with its error checks and built in help function makes it very easy for the configuration.
  • Open Source : Jenkins is open source , so its pretty much free to use and its largely backed by a huge community. You can take support from the community whether it is for errors , documentation or any other feature of Jenkins.
  • Easily Extensible : The backbone of Jenkins is the plugins, there are more than 1700+ plugins available in the update center. There are various kinds of plugins available for various purposes which can be easily integrated for deployment purposes.
  • Easy Distribution : Jenkins can be easily distributed due to its very easy procedure of installation across multiple machines for faster building , testing and deployment. You can make use of Ansible to bulk install Jenkins on multiple machines to make the work more easier.

Since we have got the basics ready, lets get started to install Jenkins on Ec2 instance.

 

Configuring Jenkins on AWS EC2 - Linux

Step 1: Create an AWS EC2 Instance

1. Login to the AWS Management console and navigate to EC2 dashboard and click on Create Instance.

2. Choose the Amazon Machine Image as Ubuntu Server.

How to install Jenkins on EC2 instance [Step-by-Step]

 

3. Now, leave the rest as default and click on Create. The EC2 Instance gets created successfully.

Advertisement

How to install Jenkins on EC2 instance [Step-by-Step]

 

Step 2: Connect the EC2 Instance

1. Select the created instance and connect it using the EC2 Instance Connect or through the SSH Client.

How to install Jenkins on EC2 instance [Step-by-Step]

 

2. The connection got established successfully.

How to install Jenkins on EC2 instance [Step-by-Step]

 

Step 3: Install Jenkins on EC2 Instance

1. We use the Debian package repository of Jenkins to automate and upgrade the installation. To use this repository, add the key to your system.

wget -q -O – https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add –

How to install Jenkins on EC2 instance [Step-by-Step]

2. Now, add the following Jenkins apt repository entry in the apt sources.

sudo vi /etc/apt/sources.list
deb https://pkg.jenkins.io/debian-stable binary/

How to install Jenkins on EC2 instance [Step-by-Step]

3. Update the apt manager sources.

sudo apt-get update

Hit:1 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal InRelease
Get:2 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:3 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB]
Get:4 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal/universe amd64 Packages [8628 kB]
Get:5 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB] 
Ign:6 https://pkg.jenkins.io/debian-stable binary/ InRelease 
Get:7 https://pkg.jenkins.io/debian-stable binary/ Release [2044 B] 
Get:8 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal/universe Translation-en [5124 kB]
Get:9 https://pkg.jenkins.io/debian-stable binary/ Release.gpg [833 B] 
Get:10 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal/universe amd64 c-n-f Metadata [265 kB]
Get:11 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal/multiverse amd64 Packages [144 kB]
Get:12 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal/multiverse Translation-en [104 kB]
Get:13 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal/multiverse amd64 c-n-f Metadata [9136 B]
Get:14 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [1400 kB]
Get:15 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal-updates/main Translation-en [283 kB]
Get:16 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal-updates/main amd64 c-n-f Metadata [14.7 kB]
Get:17 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal-updates/restricted amd64 Packages [616 kB]
Get:18 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal-updates/restricted Translation-en [88.1 kB]
Get:19 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [884 kB]
Get:20 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal-updates/universe Translation-en [193 kB]
Get:21 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal-updates/universe amd64 c-n-f Metadata [19.9 kB]
Get:22 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 Packages [24.8 kB]
Get:23 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal-updates/multiverse Translation-en [6928 B]
Get:24 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 c-n-f Metadata [616 B]
Get:25 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal-backports/main amd64 Packages [42.0 kB]
Get:26 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal-backports/main Translation-en [10.0 kB]
Get:27 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal-backports/main amd64 c-n-f Metadata [864 B]
Get:28 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal-backports/restricted amd64 c-n-f Metadata [116 B]
Get:29 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal-backports/universe amd64 Packages [18.9 kB]
Get:30 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal-backports/universe Translation-en [7492 B]
Get:31 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal-backports/universe amd64 c-n-f Metadata [636 B]
Get:32 http://us-east-1.ec2.archive.ubuntu.com/ubuntu focal-backports/multiverse amd64 c-n-f Metadata [116 B]
Get:33 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages [1069 kB]
Get:34 https://pkg.jenkins.io/debian-stable binary/ Packages [21.0 kB]
Get:35 http://security.ubuntu.com/ubuntu focal-security/main Translation-en [197 kB]
Get:36 http://security.ubuntu.com/ubuntu focal-security/main amd64 c-n-f Metadata [9096 B]
Get:37 http://security.ubuntu.com/ubuntu focal-security/restricted amd64 Packages [566 kB]
Get:38 http://security.ubuntu.com/ubuntu focal-security/restricted Translation-en [80.9 kB]
Get:39 http://security.ubuntu.com/ubuntu focal-security/universe amd64 Packages [668 kB]
Get:40 http://security.ubuntu.com/ubuntu focal-security/universe Translation-en [112 kB]
Get:41 http://security.ubuntu.com/ubuntu focal-security/universe amd64 c-n-f Metadata [13.0 kB]
Get:42 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 Packages [21.9 kB]
Get:43 http://security.ubuntu.com/ubuntu focal-security/multiverse Translation-en [4948 B]
Get:44 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 c-n-f Metadata [540 B]
Fetched 21.0 MB in 4s (5553 kB/s) 
Reading package lists... Done

4.Install JDK on Ubuntu now.

 sudo apt-get install openjdk-8-jdk

5. Install Jenkins on Ec2 instance now.

sudo apt install jenkins

How to install Jenkins on EC2 instance [Step-by-Step]

 

Step 4: Configure Jenkins

1. Once Jenkins gets installed into the ec2 instance, open a browser on your local machine and enter the URL- x.x.x.x:8080, where x.x.x.x is the public IP address of the virtual machine. A screen gets displayed where you need to enter the administrator password to unlock Jenkins.

Advertisement

2. To find the administrator password use the following command,

sudo cat /var/lib/jenkins/secrets/initialAdminPassword

How to install Jenkins on EC2 instance [Step-by-Step]

3. Login using the Administrator password and install the suggested plugins.

4. All the suggested plugins gets installed in the Jenkins environment.

How to install Jenkins on EC2 instance [Step-by-Step]

5. After installing the suggested plugins, you can create the first admin user.

How to install Jenkins on EC2 instance [Step-by-Step]

6. Once you create the user, you can start using the Jenkins environment.

How to install Jenkins on EC2 instance [Step-by-Step]

 

Step 5: Creating your first Jenkins Job

1. One can start building a project by creating a job.

How to install Jenkins on EC2 instance [Step-by-Step]

2. Enter the item name and select the Freestyle Project.

How to install Jenkins on EC2 instance [Step-by-Step]

3. Enter the description of the project.

Advertisement

How to install Jenkins on EC2 instance [Step-by-Step]

4. Select the Source code management as Git and enter the Repository URL of your code.

How to install Jenkins on EC2 instance [Step-by-Step]

NOTE:

Change the branch specifier in Source code management to */main

5.  Add the build step as execute through shell, and enter the following command to execute the HelloWorld program.

javac HelloWorld.java

java HelloWorld

How to install Jenkins on EC2 instance [Step-by-Step]

6. Finally, click on apply and save the project.

7. Now, click on build now and the project starts executing.

8. You can see the status of the execution in the Build History, below the dashboard.

How to install Jenkins on EC2 instance [Step-by-Step]

9.  Click on the Console Output to refer the detailed output.

How to install Jenkins on EC2 instance [Step-by-Step]

 

Shortcomings of Jenkins

  • Jenkins is functional driven , so its not very to easy to use and has a lot of learning curve making it hard for beginners to understand
  • It lack analytics although there are plugins that can be used , it's still not enough which makes it a headache for production team
  • Although Jenkins has lot of plugins available , the very useful ones are a few and you will have to learn to use different plugins each time you need something.
  • Jenkins plugins also has a possibility of backdoor i.e. some plugins can be created by malicious attackers and if any developer installs it then it's going to become a major issue for the organization.
  • Changes made by a developer will not be visible to another developer of the team. It makes tracking difficult in large projects.

 

Conclusion

In this article, we have learn how we can install Jenkins on ec2 instance. If you are not comfortable with Jenkins UI then you can always opt for Teamcity or GitLab. They are more easier to use compared to Jenkins ad are worth a try. If you are just getting started into DevOPs then please check out other articles on our website. Please let us know if you encounter any issues in the comments below.

 

Didn't find what you were looking for? Perform a quick search across GoLinuxCloud

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can either use the comments section or contact me form.

Thank You for your support!!

Leave a Comment

X