To configure Jenkins on AWS EC2 instance : Part One CI CD process



Login to AWS console https://aws.amazon.com/console and login using the credential.

On the Service search bar, find EC2. This will navigate to the EC2(Elastic Cloud Compute) service dashboard page.



Configure Jenkins on EC2.

Click on the Security group option on the left section to create a security group for Jenkin server. And fill the details as given in the image reference.




Fill the name, description and keep the default VPC.

For inbound rules, we can set 3 Ips HTTP, HTTPS and SSH to login to the server. Fill all the values and submit. It will create a new security group.



Next create the Key Pairs, by navigating to the key pair section.

 


Click on the Create key pair button, and fill all the relevant information.



Set any name of your wish, in file format choose pem format for ssh login on linux or unix. And ppk to access via putty on windows. I am choosing here pem. A file with private key will get download on click of create key pair. Keep this downloaded file safe for later reference to login to the EC2 instance server.

  

Next, navigate to the EC2 dashboard, to create a instance.

Click on the Launch instance button


Select the type of instance image, here for Jenkins server we use Ubuntu Machine Image. I am using here a free tier.



Choose the instance type



Configure the instance details

Select the “Enable termination protection” to checked



Keep the storage setting as default



Add the tags, added here Name => Jenkins-master, this will reflect to the EC2 dashboard



Select the security group “Jenkins-master” which created at the very beginning .



Review the instance and click on the launch button



On click the launch button, a popup appears, which ask to select or create a key pair. We already created a key-pair at the beginning. And will select that before launching the instance.



On successful creation of instance,

 


Click on the instance to get the details of the instance.



Note the Private IPv4 DNS or address .  I am using IPv4 DNS for ssh into the server.

To ssh into the created server instance, need to navigate to the directory where .pem file resides. This .pem file we created in previous steps.

ssh -i .pem file ubuntu@IPv4 DNS address.

ubuntu is a username for ubuntu instance

 


Once logged into the terminal, we can install the Jenkins and other dependency software.

For that need to run the following commands

 

Change to the root user after logging in:

    sudo su -

 

Add the aptitude key for the Jenkins application:

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

 

Add the Jenkins debian repo to the aptitude sources list:

    echo "deb https://pkg.jenkins.io/debian-stable binary/" > /etc/apt/sources.list.d/jenkins.list

 

Update the source lists and upgrade any out of date packages:

    apt update

    apt -y upgrade

 

Install the software for the Jenkins master:  openjdk-11-jdknginxand jenkins.

 

Install JDK and nginx first:

    apt -y install openjdk-11-jdk nginx

 

Then install jenkins:

    apt -y install jenkins

 

Confirm that jenkins and nginx are installed:

    systemctl status nginx  | grep Active

    systemctl status jenkins  | grep Active

 

 

On successful installation, navigate to the IPv4 public address in your favourite browser to see a initial page of Jenkins setup.


In the same terminal , where we ssh into the server, execute the command

cat /var/lib/Jenkins/secrets/initialAdminPassword

This command will return a unlock password, fill that and press continue.

 

On unlock the Jenkins , it will prompt for default plugins to get started.


Click on the Installed suggested plugins, and complete all the installation

One the installation is done, it will ask to set the username, password and other details. Add those and continue.

It will navigate to the Jenkins dashboard page





Refer the next step Part Two :  Setting a build server to run the project from Jenkins