To setup & configure Jenkins , Install Docker and Git on AWS Amazon Linux 2 AMI (HVM)
Installation & Configuration Jenkins on AWS Amazon Linux 2 AMI (HVM) — Kernel 5.10
Set up Prerequisites:
- Users have access to their AWS accounts and login using their IAM user credentials.
- Go to AWS Console->Click Services->Click EC2 under Compute->Click Launch Instance->Select Amazon Linux 2 AMI (HVM)->64-bit->Click Next
Select t2.micro General Purpose Instance->Click Next:Configure Instance Details
Change the default volume size from 8GiB to 30GiB and keep all other values as default->Click Next: Add Tags
Add Tags to your EC2 instance to label your AWS resource and easily recognize your machine for running your commands using Key,Value details ->Click Next: Configure Security Group
also add Port 8080 for the Jenkins build server to get connected.
NOTE:The source IP can change when you change your network connectivity from WiFi or any other network .So to ensure you have access to this instance go to the security group and click on My IP to capture your latest IP of the source machine->Click Review and Launch.
You can preview all the configuration details you have entered and Click Launch->It will ask you to select any key pair.If you have existing select the existing key pair,if not select Create a new key pair option->Enter the name of keypair->Click on Download key pair->and then Click Launch instances.
3: SSH to the AWS EC2 Linux Instance and run the below commands to Install & Configure Jenkins
a). First of You have install java1.8 with Amazon AMI
[ec2-user@ip-172–31–42–56 ~]$ sudo yum install java-1.8.0
[ec2-user@ip-172–31–42–56 ~]$ sudo java -version
b). Add the Jenkins repo using the following command:
[ec2-user@ip-172–31–42–56 ~]$ sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
c). Import a key file from Jenkins-CI to enable installation from the package:
[ec2-user@ip-172–31–42–56 ~]$ sudo rpm — import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key
d). Install Jenkins
[ec2-user@ip-172–31–42–56 ~]$ sudo yum install jenkins -y
e). Start Jenkins as a service:
[ec2-user@ip-172–31–42–56 ~]$ sudo systemctl start jenkins.service
[ec2-user@ip-172–31–42–56 ~]$ sudo systemctl enable jenkins.service
[ec2-user@ip-172–31–42–56 ~]$ sudo systemctl status jenkins
4: Configure Jenkins
Connect to http://<Public IP of EC2>:8080 from your favourite browser to connect to Jenkins Dashboard and you will see the below screen for the first time.
[ec2-user@ip-172–31–42–56 ~]$ sudo cat /var/lib/jenkins/secrets/initialAdminPassword
enter the password found in /var/lib/jenkins/secrets/initialAdminPassword. Use the following command to display this password->Click Continue.
- Here, I’ll choose the Install suggested plugins which will install all required apps and all needed plugins.
- After the plugins installation finishes.
The Instance configuration will provide you the Jenkins URL, just click Save and finish as shown below.
Once the installation is complete, it will ask us to create First Admin user->enter Credentials->click Save Credentials, and then click Start Using Jenkins.
Finally, You will be directed to the Jenkins Dashboard as shown, So Enjoy with Jenkins.
Access Jenkins by opening your browser then go to http://IP_address:8000
To Install Docker and Git on an Amazon EC2 instance
Update the installed packages and package cache on your instance.
[ec2-user@ip-172–31–42–56 ~]$ sudo yum update -y
Install the most recent Docker Engine package.
[ec2-user@ip-172–31–42–56 ~]$ sudo yum install docker
Start the Docker service.
[ec2-user@ip-172–31–42–56 ~]$ sudo systemctl start docker
[ec2-user@ip-172–31–42–56 ~]$ sudo systemctl enable docker
[ec2-user@ip-172–31–42–56 ~]$ sudo systemctl status docker
[ec2-user@ip-172–31–42–56 ~]$ sudo yum install git -y
How to Create a New Build Job in Jenkins
Step by Step process to create job in Jenkins
Step 1) Login to Jenkins
To create a Jenkins freestyle job, log on to your Jenkins dashboard by visiting your Jenkins installation path. it will be hosted on localhost at http://localhost:8080
Step 2) Create New Item
Click on “New Item” at the top left-hand side of your dashboard.
Step 3) Enter Item details
In the next screen,
- Enter the name of the item you want to create. We shall use the “my_1_project” for this demo.
- Select Freestyle project
- Click Okay
Step 4) Enter repository URL
Under Source Code Management, Enter your repository URL. We have a test repository located at https://github.com/sonamsks/httpbin.git
Step 5) Tweak the settings
Now that you have provided all the details, it’s time to build the code. Tweak the settings under the build section to build the code at the time you want. You can even schedule the build to happen periodically, at set times.
1. Click on “Add build step”
2. Click on “Execute shell” and add the commands you want to execute during the build process.
Step 6) Save the project
When you have entered all the data,
- Click Apply
- Save the project.
Step 7) Build Source code
Now, in the main screen, Click the Build Now button on the left-hand side to build the source code.
Step 8) Check the status
After clicking on Build now, you can see the status of the build you run under Build History.
Step 9) See the console output
Click on the build number and then Click on console output to see the status of the build you run. It should show you a success message, provided you have followed the setup properly as shown in the below Jenkins create new job example.
In sum, we have executed a my_1_project program hosted on GitHub. Jenkin pulls the code from the remote repository and builds continuously at a frequency you define.