AWSJenkins

Jenkins Installation on AWS EC2 Linux Instance

This blog will guide you through a detailed but yet easy steps for Jenkins installation on AWS ec2 linux instance. However in order to launch linux instance on AWS, follow this blog.

If you want to see the video for this article, click here

Prerequisite:

Java 8 is a prerequisite. To Install Oracle JDK,  Click here to install Java.

Follow this article to install openjdk
sudo yum install wget
yum install java-1.8.0-openjdk
Configure Java HOME
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.252.b09–2.amzn2.0.1.x86_64
export PATH
sudo alternatives --config java

Jenkins installation on AWS ec2 linux instance:

Step 1. Firstly, add Jenkins repository using wget, so that yum get to know where to install Jenkins from.

Install wget ,if not installed
sudo yum install wget
[ec2-user@ip-xxx-xx-xx-xx]$ sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo

*yum is the package manager which can install, remove, update software and can manage all the dependencies for each packages.

Image for post

Step 2. Now, let’s add the Jenkins GPG key to our trusted keys, so that we will be able to verify/trust the files that are being sourced (while installing Jenkins )are from trusted site.

[ec2-user@ip-xxx-xx-xx-xx]$ sudo rpm --import https://pkg.jenkins.io/redhat/jenkins.io.key

As now, the environment has been prepared and has resolved the required dependencies, lets install Jenkins.

[ec2-user@ip-xxx-xx-xx-xx]$ sudo yum install jenkins
Image for post

Step 3. Jenkins services needs to be started, with the following command:

[ec2-user@ip-xxx-xx-xx-xx]$ sudo service jenkins start
Image for post

*If you wish to start Jenkins automatically when your linux instance is started, then you can use chkconfig to add Jenkins to your startup services.

[ec2-user@ip-xxx-xx-xx-xx]$ sudo chkconfig --add jenkins

Step 4. Make sure to open port 8080 (default port to which Jenkins listen):

(i) Go to your AWS management console → ec2 dashboard → Network & Security → Choose the security group of your instance

Image for post
Image for post

Click on the Inbound tab

Image for post

Click on edit → Add rule : Custom TCP with Port range 8080

Image for post

Step 5. Go to your browser and connect to jenkins via default port 8080

Image for post

Step 6. To unlock jenkins fetch the administrator password by typing following command:

[ec2-user@ip-xxx-xx-xx-xx]$ sudo cat /var/lib/jenkins/secrets/initialAdminPassword

Step 7. Click on ‘Install suggested plugins’ in the customize Jenkins window.

Image for post
Image for post

Step 8. Create first admin user:

Specify username, password and other details.

Image for post
Image for post
Image for post
Image for post
Image for post
Image for post

Setup Jenkins to run as a different user

  • Edit /ect/sysconfig/jenkins
  • Change the JENKINS_USER to the new user
Image for post

Finally congratulations!! You have successfully followed each and every step for Jenkins installation on AWS ec2 linux instance.