Jenkins installation on AWS Linux Amazon EC2

Faroug Mohammed
5 min readFeb 16, 2021

This story aims to configure a CI/CD that spans multiple AWS accounts (Development, Staging and Production) we’ll use it to builds and deploy the angular single page application (front-end) builds and maven spring-boot Applications (Back-end) to their respective environments, security and as well as we will see how to migrate a Jenkins installed over an operating system to docker and run it on AWS ECS. I’ll divide it into multiple parts.

Note this tutorial aimed at those who know AWS, Docker and Jenkins and other tools that I’m going to use.

Assuming that you have an AWS account and administrative permission. we’ll be using the default VPC to launch our Jenkins server

Let’s start at configuring a Jenkins Server run on EC2 Amazon Linux AMI with AWS credentials…

You can also refer to the official installation document provided by Jenkins — https://www.jenkins.io/doc/tutorials/tutorial-for-installing-jenkins-on-AWS/

by using the navigation search bar or services drop-down button type to the EC2 as it’s highlighted in the below photo.

On the EC2 Dashboard Press the Orange Launch Instance button.

Select the Amazon Linux 2 AMI “Free tier eligible”.

On the Instance Type page leave it to the default t2.micro with the Free tire eligible as we provisioning a Free Tire Eligible resource to refrain from cost incurred. Press Next: Configure Instance Details

Make sure that the Auto-assign Public IP is Enabled, and that is for now later we will change other configuration as we will attach an IAM Role to the EC2 instance.

On the next Storage Page, Add extra storage to the root volume as the Jenkins configuration folder will reside on the/var/lib/Jenkins folder
Note as per AWS Shared Responsibility Model Customers are responsible for managing their data (including encryption options) so it’s highly recommended to encrypt your data and the easiest way is to use the Key Management Keys Services (KMS) provided by AWS you can skip it if you wish.

Tagging is a great way provided by AWS helps in controlling the resources or having a cost allocation based on the tags to learn more AWS Tagging link

On the Configuring Security Group add a custom TCP Port with value 8080 and source anywhere

After the launch waits until the Instance state change to Running as you can see below.

Now for the Jenkins installation, I’ll show two ways

  • Directly installation on the Amazon Linux OS
  • Using Docker to see how we can migrate the Jenkins configuration and use it wherever we want.

Accessing the server use terminal for mac and Linux or git bash for windows:

$ ssh -i /path/my-key-pair.pem ec2-user@ec2–198–51-100–1.compute-1.amazonaws.com

(Optional): you can skip
If you want to use a customized-name as a command

$ ssh jenkins# Do the following:

$ mv jenkinskeypair.pem ~/.ssh
$ ll jenkinskeypair.pem
$ chmod 400 jenkinskeypair.pem
# create a config file use text editor:
$ nano config
Host jenkins
Hostname Jenkins-Public-IP
User ec2-user
IdentityFile ~/.ssh/jenkinskeypair.pem
and save it by Ctrl+x

Using SSH to connect to your instance (server)

$ ssh jenkins

Download and install Jenkins on the Amazon Linux OS

To download and install Jenkins:

  • To ensure that your software packages are up to date on your instance, use the following command to perform a quick software update:
[ec2-user ~]$ sudo yum update –y
  • Add the Jenkins repo using the following command:
[ec2-user ~]$ sudo wget -O /etc/yum.repos.d/jenkins.repo \
https://pkg.jenkins.io/redhat-stable/jenkins.repo
  • Import a key file from Jenkins-CI to enable installation from the package:
[ec2-user ~]$ sudo rpm — import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
[ec2-user ~]$ sudo yum upgrade
  • Install Jenkins, Git and OpenJDK Java 8:
[ec2-user ~]$ sudo yum install jenkins java-1.8.0-openjdk-devel git -y
[ec2-user ~]$ sudo systemctl daemon-reload
  • Start Jenkins as a service:
[ec2-user ~]$ sudo systemctl start jenkins

You can check the status of the Jenkins service using the command:

[ec2-user ~]$ sudo systemctl status jenkins

You can check the git and java installation using the command:

[ec2-user ~]$ git — version
[ec2-user ~]$ java -version

Download and install Jenkins using Docker

--

--