Configuring Jenkins on AWS EC2 Instance
Tags: jenkins, devops
Published: 2021-07-01 19:26:54

This post provides an overview of the steps required to install and run  [Jenkins](https://www.jenkins.io/)  Server on Amazon Linux 2. By the end of the post, we will have a working Jenkins Server ready to configure pipelines.

 Jenkins can be installed in  [numerous ways](https://www.jenkins.io/doc/book/installing/)  - Native system packages, Docker, standalone executable session. This post will be focused on native package installation.

Jenkins recommends the following [minimum hardware requirements](https://www.jenkins.io/doc/book/installing/linux/) for Server configuration

- 1 CPU
- 256 MB of RAM
- 1 GB of drive space (although 10 GB is a recommended minimum if running Jenkins as a Docker container)

For Demo purposes, we can select the `T2 micro` instance type as it satisfies the above minimum criteria.

####  Prerequisites
- AWS Cloud Account (Free tier will work)
- A EC2 instance running with `T2 micro` for instance type
- AWS key-pair to `SSH` into the EC2 instance
- Configure firewalls (security groups) to allow SSH access into the EC2 instance


#### Installation Steps
**Step 1.** Initiate an SSH session into your Amazon Linux - EC2 instance.

![Screenshot 2021-06-28 at 12.29.27 PM.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1624863709569/NozCbQHxx.png)

**Step 2.** Update existing installed packages on the EC2 instance
```bash
sudo yum update -y
```
**Step 3.** Install most recent Open JDK (Java ver 11). Required for Jenkins installation
```bash
sudo amazon-linux-extras install java-openjdk11 -y
```

**Step 4.** Add Jenkins repo to Amazon Linux 2 server
```bash
sudo tee /etc/yum.repos.d/jenkins.repo<<EOF
[jenkins]
name=Jenkins
baseurl=http://pkg.jenkins.io/redhat
gpgcheck=0
EOF
```

**Step 5.** Import GPG Jenkins repo key
```bash
sudo rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key
```

**Step 6.** Update list of repositories
```bash
sudo yum repolist
```

**Step 7.** Install Jenkins in Amazon Linux 2 server 
```bash
sudo yum install jenkins -y
```

**Step 8.** Start Jenkins service
```bash 
sudo systemctl start jenkins
```

**Step 9.** Enable Jenkins service to start at OS boot
```bash
sudo systemctl enable jenkins
```

**Step 10.** Confirm that the Jenkins Service is up and running
```bash
sudo systemctl status jenkins
```
![Screenshot 2021-06-28 at 12.47.13 PM.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1624864854868/en47NNOpY.png)

**Step 11.** Validate if the Jenkins service is configured to autostart on system reboot.
```bash
sudo systemctl is-enabled jenkins
```
![Screenshot 2021-06-28 at 12.51.18 PM.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1624865006355/prIa1BQ9G.png)

**Step 12.** Access Jenkins Server on EC2 instance
Jenkins service by default binds to port 8080. It will be accessible on
```http
http://[server-ip-or-hostname]:8080
```
For the first time, Jenkins will prompt the `Unlock Jenkins` screen to authenticate the installation.

![Screenshot 2021-06-28 at 1.02.15 PM.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1624866113425/q2ERaD2Pu.png)

**Step 13.** Fetch password to Unlock Jenkins.
As advised the following command will provide the relevant password
```bash
cat /var/lib/jenkins/secrets/initialAdminPassword
```

Copy the automatically-generated alphanumeric password (between the 2 sets of asterisks). On the Unlock Jenkins page, paste this password into the Administrator password field and click **Continue**.

**Step 14.** Customize Jenkins
Recommended selecting `Install suggested plugins` to install the recommended set of plugins based on most common use cases.

![Screenshot 2021-06-28 at 5.08.29 PM.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1624880620152/bVw_YaEOn.png)

The setup wizard shows the progression of Jenkins plugins being installed
![Screenshot 2021-06-28 at 5.12.11 PM.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1624880667331/3hPQc-7yx.png)

**Step 15.** Create First Admin User
Enter relevant details to create Admin User and click ** Continue **
![Screenshot 2021-06-28 at 5.13.41 PM.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1624880805475/inX_iiXBA.png)

**Step 16.** Configure Valid DNS (if required)
Jenkins Instance access URL will be printed on the screen that follows. This can be changed with a valid DNS name. For the purpose of our demo, we will leave it unchanged and click ** Save and Finish **

![Screenshot 2021-06-28 at 5.17.35 PM.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1624881145697/a2vgnJz3F.png)

**Step 17.** Jenkins is ready, Hurray!! You have now successfully configured Jenkins.
![Screenshot 2021-06-28 at 5.20.58 PM.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1624881227147/ZTybKtcS5Q.png)

Jenkins Dashboard
![Screenshot 2021-06-28 at 5.24.40 PM.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1624881410926/Fkv07tg3J.png)