Day-22: Getting Started with Jenkins

Day-22: Getting Started with Jenkins

Β·

5 min read

What is Jenkins?

Jenkins is an open-source continuous integration-continuous delivery and deployment (CI/CD) automation software DevOps tool written in the Java programming language. It is used to implement CI/CD workflows, called pipelines.

Jenkins is a tool that is used for automation, and it is an open-source server that allows all the developers to build, test and deploy software. It works or runs on Java as it is written in Java. By using Jenkins we can make a continuous integration of projects(jobs) or end-to-endpoint automation.

Jenkins achieves Continuous Integration with the help of plugins. Plugins allow the integration of Various DevOps stages. If you want to integrate a particular tool, you need to install the plugins for that tool. For example Git, Maven 2 project, Amazon EC2, HTML publisher, etc.

Why we should use Jenkins?

  • Open Source with great community support.

  • A lot of plugins

  • Easy to Install

  • Free of cost

  • It is built with Java and hence, it is portable to all the major platforms.

What is CI/CD?

CI means Continuous Integration Continuous Integration is used to automate pulling the code from source code management, building, and testing. CD means Continuous Delivery/Deployment is used to automate the deployment of build code with help of manual Intervention. Finally, the CD is Continuous Delivery/Deployment which will automate the deployment as well without manual intervention.

What is Plugin?

A plugin is a software add-on that is installed on a program, enhancing its capabilities. Plugins allow the integration of Various DevOps stages. If you want to integrate a particular tool, you need to install the plugins for that tool. For example Git, Maven 2 project, Amazon EC2, HTML publisher etc.

Installation of Jenkins

To download and install Jenkins on various OS you can visit the link Download Jenkins.

Here we will install and use Jenkins on Ubuntu OS. Follow the below steps

- Here you can see the installation guide on Jenkin on Linux

Step 1: Install Java

  • Create an AWS EC2 Instance AMI of your choice I am picking up Ubuntu.

  • Jenkins requires the Java Runtime Environment (JRE) required to run the Jenkins because Jenkins is written in Java.

  • Connect to the AWS EC2 instance and update the system and Check if you already have Java installed on your Ubuntu system

    To update the system sudo apt update

    To check the Java version java --version

  • Depending on which Java version you want to install, Java 8 or 11, run one of the following commands:

    • To install OpenJDK 8, run: sudo apt install openjdk-8-jdk -y

    • To install OpenJDK 11, run: sudo apt install openjdk-11-jdk -y

Step 2: Add Jenkins Repository

It is recommended to install Jenkins using the project-maintained repository, rather than from the default Ubuntu repository. The reason for that is because the Jenkins version in the default Ubuntu repository might not be the latest available version, which means it could lack the latest features and bug fixes.

  • Start by importing the GPG key. The GPG key verifies package integrity but there is no output.

    Run:

      curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee \
        /usr/share/keyrings/jenkins-keyring.asc > /dev/null
    

  • Add the Jenkins software repository to the source list and provide the authentication key:

      echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
        https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
        /etc/apt/sources.list.d/jenkins.list > /dev/null
    

Step 3: Install Jenkins

  • Update the system repository using:

    sudo apt update

  • Install Jenkins by running:

    sudo apt install jenkins -y

  • To check if Jenkins is installed and running, run the following command:

    To check Jenkins's version jenkins --version

    To check Jenkins's status sudo systemctl status jenkins

    To start Jenkins's sudo systemctl start jenkins

Step 4: Allow port 8080 in EC2 instance

As we know Jenkins works on port 8080 so we need to allow port 8080 in the security group of the EC2 instance

Go to the EC2 instance -> in the security click on Security Groups click on Edit inbound rules add Custom TCP as port 8080 and click on save.

Step 5: Access the Jenkins

  • Now Copy your Instance Public Ip and Add 8080 to it to go to the Jenkins page. <Public-IP>:8080 and paste in the browser and you will see the start-up page on Jenkins

  • To ensure Jenkins is securely set up by the administrator, a password has been written to the log (not sure where to find it?) and this file on the server:

    /var/lib/jenkins/secrets/initialAdminPassword open the file using cat command

       cat /var/lib/jenkins/secrets/intialAdminPassword
    

  • Please copy the password from either location and paste it into the Administrator password and click on continue.

  • Next, select Install suggested plugins

  • Now create the first admin user by providing the below information and click on save and continue.

  • Now you will come to the Instance Configuration page keep it as it is as a Jenkins URL and click on Save and Finish

  • ***BOOOOOOOOOOMMMMMMM....***πŸ•ΊπŸ•ΊπŸ‘πŸ‘πŸŽ‰πŸŽ‰We have successfully installed Jenkins

    Now click on Start Using Jenkins

  • Now you will see the Jenkins dashboard

Create a freestyle project to print "Hello World!!

  • Click on Create a job or New Item or Click on Create a job

  • Enter Job Name and Select Freestyle project and click on ok

  • Enter the description as per your wish

  • Now go to Build Steps and select Execute Shell (It is used to run Linux or shell commands).

  • Now enter the command you want to execute then click on Apply and Save .

  • Now Click on Build Now then in Build History #1 will be created and ckck on it to see the Console Output.

  • Let's click on the Console Output and see the output as expected

    ***BOOOOOOOMMMMMMM...***We have successfully created a job in Jenkins to run Hello World and We can see the output in Console. Congratulations πŸ’πŸ’ on your first job in Jenkins πŸŽ‰πŸŽ‰.


    Thank you for reading the article.

    Thanks for your valuable time.

    Happy Learning !... Keep Learning ! 😊

Β