Jenkins is an open-source continuous integration and continues development tool. In this tutorial, I will explain the installation of Jenkins server on AWS EC2 instance. Here, I am using Amazon Linux [Amazon Linux AMI 2018.03.0 (HVM), SSD Volume Type – ami-00eb20669e0990cb4 } as my OS. At the time of instance lunch, make sure you have added an inbound rule for 8080 port. Once you launched the EC2 instance, log in to the machine with the help of the private key.
Switch to root for installing the Jenkins server.
[ec2-user@ip-172-31-94-244 ~]$ sudo su - [root@ip-172-31-94-244 ~]#
Jenkins is a java-based program, so we need to make sure that java installed. Execute the below command to check the Java version.
[root@ip-172-31-88-176 ~]# java -version java version "1.7.0_231" OpenJDK Runtime Environment (amzn-22.214.171.124.80.amzn1-x86_64 u231-b01) OpenJDK 64-Bit Server VM (build 24.231-b01, mixed mode)
The default installed Java version is 1.7.0_23 but, I will remove and install 1.8 version. (Jenkins will work fine on Java-1.7 but I decided to use the new version.
Execute below command to remove the Java 1.7 version.
yum remove java-1.7.0*
Next, install java-1.8, for this execute below command.
yum install java-1.8* -y
Just confirm that we have installed the correct version by executing the below command.
[root@ip-172-31-88-176 ~]# java -version openjdk version "1.8.0_222" OpenJDK Runtime Environment (build 1.8.0_222-b10) OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)
Installation is done. Next, we have to set Java home path.
Find out where is JRE by executing the below command.
[root@ip-172-31-88-176 ~]# find /usr/lib/jvm/java-1.8* | head -n 3 /usr/lib/jvm/java-1.8.0 /usr/lib/jvm/java-1.8.0-openjdk /usr/lib/jvm/java-1.8.0-openjdk-126.96.36.199.b10-0.47.amzn1.x86_64
Do an “ls -l ” on the third path and you can see our “JRE” path.
ls -l /usr/lib/jvm/java-1.8.0-openjdk-188.8.131.52.b10-0.47.amzn1.x86_64 total 50892 drwxr-xr-x 2 root root 4096 Nov 3 04:32 bin drwxr-xr-x 10 root root 4096 Nov 3 04:32 demo drwxr-xr-x 3 root root 4096 Nov 3 04:32 include drwxr-xr-x 4 root root 4096 Nov 3 04:32 jre
Copy the path and add it in the bash profile file.
Add the below code or modify it based on your profile file.
Execute an echo command to confirm we set the correct path. Please note the first time it won’t show the correct path so log out and log in again.
[root@ip-172-31-88-176 ~]# echo $JAVA_HOME /usr/lib/jvm/jre [root@ip-172-31-88-176 ~]# logout [ec2-user@ip-172-31-88-176 ~]$ sudo su - Last login: Sun Nov 3 04:24:45 UTC 2019 on pts/0 [root@ip-172-31-88-176 ~]# echo $JAVA_HOME /usr/lib/jvm/java-1.8.0-openjdk-184.108.40.206.b10-0.47.amzn1.x86_64 [root@ip-172-31-88-176 ~]#
Install the required repository and add the corresponding key, for this execute below command. These repository details can be found from the below link. Follow the steps mentioned in the page.
wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhatstable/jenkins.repo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
Next, install Jenkins service with the help of yum.
yum install -y jenkins
Start the service
# service jenkins start Starting Jenkins [ OK ]
Now try to access the service on the browser. Copy the server IP address and paste it on the browser.
To get the Admin password copy and paste the mentioned file.
[root@ip-172-31-88-176 ~]# cat /var/lib/jenkins/secrets/initialAdminPassword 1b2a83040c28447e865b6
Paste the password in the box and click on the “Continue ” button.
On the next page, you will get an option to install the plugins. If you required you can install the suggested plugin or you can do it later. Next page you can create an admin user or skip it. I skipped and completed the installation.
Next page you will get a message displays the Jenkins installation is completed.
Change admin password
Click on “Start using Jenkins” to start it. Once you logged in you can change the admin password by selecting admin (Top right corner) and click on Configuration. Add a new password in the mentioned field.
Set Java home path
To set Java path click on Manage Jenkins from the left side panel.
Next page click on Global Tool Configuration and then click on the “Add JDK” button.
Give a name and deselect “Install automatically” option and add the java home path. Please refer below screenshot.
Click apply and then save it.
Executing the first job
We will create a test job on Jenkins for this click on “New item” from the left side panel.
Give a name and select the Freestyle project.
Click on to continue. On the next page add a description of your job and select Source code management as none.
Next one we have to choose a Build, I have chosen Execute shell and added a shell code. With will display output as “Hello!! Welcome to Jenkins’s job”.
Click the Save button to save it.
To build our job click on “build now” or if you want to modify click on configure.
Click on Build now to run the code. Under the left side panel, you can see a blue ball which indicates that the build is successful. If it in the red color then the build is failed.
Click the blue ball to see the console output.
From the output, it is clear the job is executed by admin user and the output is
“Hello!! welcome Jenkins job” and it finished successfully.
Jenkins server installation and configurations are completed.