Installing Jenkins on EC2 Instance: A Step-by-Step Guide 2024 | Setting Up Jenkins on AWS EC2: A Quick Installation Guide 2024
In this article you will learn how to install jenkins on ec2 machine in quickest way possible.
Along with that you will learn to create a jenkins job which has github webhook enabled so that once the commit push to github the job will triggered automatically.
Step 1: Launching an EC2 instance
Here we launching ec2 instance which has user data which automatically installed the git and jenkins inside the ec2 instance. Here are the steps:
- After signing to aws console, Go to ec2 dashboard.
- In the resources section, select instances(running).
3. Now select launch instances.
4. Enter server name, select ami (amazon linux), and instance type(t2.micro).
5. Create a key pair to securely connect to our ec2 instance.
6. Now select Advanced details and search for the user data option.
7. In the user data option, write the commands that will install git and Jenkins inside the server when the instance is launched, so we don’t have to manually enter the commands.
#!/bin/bash sudo yum update -y sudo yum install git -y sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key sudo yum upgrade sudo dnf install java-17-amazon-corretto -y sudo yum install jenkins -y sudo systemctl enable jenkins sudo systemctl start jenkins
https://www.jenkins.io/doc/book/installing/linux/
8. Once the instance is launched successfully, we need to ssh into it. Copy the example command and run the command in the cmd in the directory where you download the pem file (key pair).
9. Now run the sudo bash to run as admin then check if jenkins is running properly or not by usiing this command:
systemctl status jenkins
10. Now try to run the Jenkins application on the browser by running ip:8080.
The site can’t be reached because the security group is not permitted to view the 8080 port of that server publically.
We have to add inbound rules that allow this
Step 2: Configuring Jenkins
Now after installation, need to setup jenkins by unlocking jenkins using administrator password:
cat /var/lib/jenkins/secrets/initialAdminPassword
it will give you the password.
Create first admin user by adding username, password, fullname, and email. After that just continue and the jenkins configuration is done.
Here you will see the jenkins dashboard.