Tutorial for Installing Jenkins on AWS | Windows 

Jenkins is an open-source automation software to implement pipeline workflows for CI/CD (continuous integration, delivery and deployment).
article cover

Jenkins is an open-source automation software to implement pipeline workflows for CI/CD (continuous integration, delivery and deployment).

Jenkins is a DevOps tool built with Java that integrates with several AWS services. These services include Amazon EC2 Spot and Fleet, AWS CodeCommit, and AWS CodeDeploy 

You can deploy a Jenkins application to Amazon Web Services (AWS) using Amazon Elastic Compute Cloud (Amazon EC2). To do this, you need to set up an EC2 instance, install Jenkins on that instance, and configure Jenkins to use the EC2 instance on AWS.

This tutorial covers the following procedures on a Windows system OS:

  • Opening an account on Amazon Web Services (AWS) if you do not already have one.
  • Generating a key pair for your application with Amazon EC2.
  • Creating a security group for your Amazon EC2 instance.
  • Launch an Amazon EC2 instance.
  • Install and configure Jenkins.
  • Windows Operating system 
  • Cleaning up the resources of the tutorial.

Table of Contents

Prerequisites:

  • Amazon Web Services (AWS) account. Sign up here if you don’t already have an account.
  • A key pair for use with Amazon EC2. See Generate a key pair section below if you don’t have a key pair.

Generate a key pair:

Note: When installing Jenkins, generating a key pair helps to ensure that the correct type of authentication is used.

Follow the steps below to generate a key pair:

  1. Log in to https://console.aws.amazon.com/ec2 to access the Amazon EC2 console.
  2. Select Key Pairs from the available options in the NETWORK & SECURITY section of the navigation pane.
  3. Select Create key pair.
  4. In the Name field, enter a name that describes the key pair. Amazon EC2 associates the name you specify as the key name with the public key. A key name can contain up to 255 ASCII characters. It cannot contain any spaces before or after the name.
  5. Select the format to save the private key under the private key file format.
    1. Select pem for OpenSSH compatibility.
    2. Select ppk for PuTTY compatibility.
  6. Select Create key pair, and the private key file is automatically downloaded. 
  • The base file name is the name you gave your key pair.
  • The filename extension is based on the file format you chose. 
  • Keep the private key file in a safe place.

Note: This is your only chance to save the private key file.

Create a security group.

A security group controls the traffic that can reach one or more EC2 instances. It works like a firewall. You can assign one or more security groups to an instance when you launch it. Within each security group, you add rules that control the types of traffic allowed to reach the instances. You can change the rules for a security group anytime, and these changes take effect immediately.

To complete this tutorial, you must create a security group and add the following rules:

  • Authorise HTTP connections from anywhere.
  • Authorise incoming SSH traffic from the public IP address associated with your computer to connect to your instance.

Create and configure your security group by doing the following:

1. Determine who is allowed to access your instance. As an illustration, a single computer or all of the reliable computers are connected to a network. For this tutorial, you can use the public IP address of your computer.

  • To find your IP address, you can either use the check IP service tool available on AWS3 or search any search engine using the phrase what is my IP address.
  • If you do not have a static IP address, use the range of IP addresses used by client computers to connect through an Internet Service Provider (ISP) or behind your firewall. If you are not familiar with this range of addresses, use the notation 0.0.0.0/0 for this tutorial.

NoteBecause the IP address grants SSH access to anyone on the network, you should not use this configuration in environments that are used for production.

2. Launch the AWS Management Console and sign in.

3. Launch the Amazon EC2 console by going to the Compute menu and selecting EC2.

4. From the Resources list, select Security Groups.

5. Click Create Security Group.

6. In the Security group name field, type WebServerSG or any preferred name you choose. Add a description and choose your virtual private cloud (VPC) from the list. You can use the VPC that you initially set up.

7. In the Inbound rules section, add the following rules:

SSH Rule:

  1. Click Add Rule.
  2. Select SSH from the Type drop-down menu. 
  3. Select Custom from the Source drop-down menu. 
  4. In the text box, enter the IP address obtained when creating a security group, followed by /32 to indicate a single IP address. To automatically generate your IP address, in the Source section, click on My IP.

HTTP Rule:

  1. Click Add Rule. 
  2. Select HTTP from the Type drop-down menu. 
  3. Select Custom from the Source drop-down menu. 
  4. In the text box, enter 0.0.0.0/0 as the IP address.

Custom TCP Rule:

  1. Click Add Rule. 
  2. Select Custom TCP from the Type drop-down menu.
  3. Enter 8080 in the Port range.
  4. Select Custom from the Source drop-down menu. 
  5. In the text box, enter 0.0.0.0/0 as the IP address.

8. Click Create security group.

Note: Please refer to the Security Groups section of the Amazon EC2 User Guide for Linux Instances, for any additional information.

Launch an Amazon EC2 instance

Now that you have configured a key pair and security group, you can launch an EC2 instance.

To launch an EC2 instance:

  1. Sign in to the AWS Management Console.
  2. Select EC2 under Compute to open the Amazon EC2 console.
  3. In the Amazon EC2 dashboard, select Launch Instance.
  1. Select the Amazon Linux 2 AMI. It displays a list of basic configurations called Amazon Machine Images that serve as templates for your instance. 
  2. Select the HVM (Kernel 5.10. edition of the Amazon Linux AMI.
  1. On the Instance Type page, the t2.micro instance is selected by default. Verify that this instance type is selected to stay within the free tier.
  1. To edit the security group, scroll down to Network Settings and select the existing security group, WebServerSG, in this case. 
  1. In the Key Pair (Login) section, select an existing key pair (if you created one above) or create a new key pair.
  1. Click Launch Instance, and a successful dialogue will be displayed.
  1. Click Instances to view the status of your newly created instance. Initially, the status of your instance is Pending. Your instance is ready for use when the status changes to Running.

Install and configure Jenkins

Now that the Amazon EC2 instance has been launched, let’s connect it to our Linux instance and set up Jenkins. This section describes the following steps to set up Jenkins on your EC2 instance:

  • Connect to your Ec2 instance
  • Download and install Jenkins
  • Configure Jenkins

Connect to your Amazon EC2 instance.

Once your EC2 instance has been successfully launched, you can connect to it and use it as you would on your local machine. To connect to your instance, you need its public DNS name from the Amazon EC2 console.

To get the public DNS name:

  1. In the Amazon EC2 dashboard, select your instance.
  2. Click on the copy icon in the Public IPv4 DNS field and paste it somewhere for later.

Prerequisites

How you connect to your Linux instance is dependent on the operating system you use.

  • For Windows OS, use PuTTY to connect.
  • For Linux or Mac OS X, use the SSH client to connect.

These tools require a key pair to function correctly. If you’ve not created a key pair, follow the instructions in Creating a key pair above.

In this tutorial, we use PuTTY to connect to the instance from a local Windows computer.

Connect to your instance with PuTTY

To connect to your instance using PuTTY:

  1. Install PuTTY on your local computer.
  2. Navigate to the Start menu and select All Programmes > PuTTY.
  3. In the Category pane, select Session.
  4. In Host Name, enter the Public IPv4 DNS you copied earlier.
  5. Ensure that Port is 22.
  1. In the Category pane, navigate to Connection SSH Auth.
  2. Click Browse.
  3. Select the .ppk file you generated for your key pair, as described in Creating a key pair.
  1. Click Open to start the PuTTY session.
  2. To log in, type ec2-user and press Enter. You will be connected to the ec2 instance. 

Yeah!!! We have successfully connected to our EC2 instance.

Download and Install Jenkins

This section describes downloading and installing Jenkins on your EC2 instance using PuTTY.

To download and install Jenkins:

  1. Ensure you are currently logged in to your EC2 instance as ec2-user. To check which user you are currently logged in as: 
sudo su
  1. To switch to ec2 user : 
sudo su ec2-user
  1. 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
  1. 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
  1. 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
  1. Install Java: 
[ec2-user ~]$ sudo yum install java-openjdk11 -y
  1. Install Jenkins: 
[ec2-user ~]$ sudo yum install jenkins -y
  1. Enable the Jenkins service to start at boot: 
[ec2-user ~]$ sudo systemctl enable jenkins
  1. Start Jenkins as a service: 
[ec2-user ~]$ sudo systemctl start jenkins
  1. Check the status of the Jenkins service using the command: 
[ec2-user ~]$ sudo systemctl status jenkins

Configure Jenkins

After successfully installing Jenkins on your Windows OS with the above command, Jenkins is now installed and running on your EC2 instance. To configure Jenkins, complete the following steps:

  1. Connect to http://<your_server_public_DNS>:8080 from your web browser. This gives you access to Jenkins through its management interface.
  2. When prompted, enter the password found in /var/lib/jenkins/secrets/initialAdminPassword. You can also use the following command to display the password: 

[ec2-user ~]$ sudo cat /var/lib/jenkins/secrets/initialAdminPassword

Once the password is revealed, enter it in the Administrative Password to log in.

  1. If you are installing Jenkins for the first time, the dashboard requires you to install the recommended plugins. Click to install suggested plugins.
  2. Once the installation is complete, enter your information in the Create First Admin User window.
  3. Click Save and Continue.
  1. After creating your account, log into the Jenkins dashboard using your First Admin User credentials.

Setup Java.

This section describes how to set up Java on Jenkins to create your Jenkins build.

  1. In the left navigation of the Jenkins dashboard, click Manage Jenkins > Global Tool Configuration.
  1. Under the JDK section, Click Add JDK
  2. Uncheck Install automatically.
  3. Enter your Java path in the JAVA_HOME field.
  4. Click Save.

Create a Jenkins project.

  1. In the left-side navigation of the Jenkins dashboard, click New Item.
  2. Enter your project name.
  3. Select Freestyle Project.
  4. Click OK.
  1. Click Build Environment
  2. In the build section, click Add build step > Execute shell. Type this code:
echo “My DevOps Journey just started!!!”
  1. Click Save.
  2. Click on Build Now. Then click on #1. A success message shows that you have successfully built your Jenkins Project on the EC2 Instance.

Cleaning up.

After this tutorial, it is important to ensure that all created AWS resources are deleted to avoid additional costs.

To delete the resources:

  1. In the Amazon EC2 console, navigate to Instances in the left side navigation. 
  2. Right-click the instance you created earlier and select Terminate instance. This terminates your Amazon EC2 instance and deletes all its resources.

Conclusion

This post covers instructions for installing Jenkins on AWS. Follow this blog for more releases and updates.

If you find this article useful, don’t forget to hit the clap button or leave a comment if you have any questions. Also, feel free to ask questions or contribute to my conversation on Twitter.

Leave a Reply

You might also like...

Why You Should Have Technical Writers on Your Team

Technical writers complete the puzzle in a technical team. Their primary role is to communicate complex, technical information clearly and concisely. A technical writer communicates and translates complex information into

Are you ready?

Let's get started

Terms & Conditions

Copyright © 2024. WriteTech Hub. All rights reserved.