๐Ÿš€Day 22:  Getting Started with Jenkins ๐Ÿ˜ƒ

๐Ÿš€Day 22: Getting Started with Jenkins ๐Ÿ˜ƒ

Linux, Git, Git-Hub, Docker finish ho chuka hai to chaliye seekhte hai inko deploy krne ke lye CI-CD tool:

ยท

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.

Let us do discuss the necessity of this tool before going ahead to the procedural part for installation:

  • Nowadays, humans are becoming lazy๐Ÿ˜ด day by day so even having digital screens and just one click button in front of us then also need some automation.

  • Here, Iโ€™m referring to that part of automation where we need not have to look upon a process(here called a job) for completion and after it doing another job. For that, we have Jenkins with us.

  • Jenkins plays a crucial role in modern software development practices by automating and streamlining key processes in the CI/CD pipeline. Its extensibility, flexibility, and robust feature set make it a valuable tool for teams aiming to enhance efficiency, collaboration, and the overall quality of software delivery. Now, understanding its necessity, let's proceed with the procedural part of Jenkins installation.

JENKINS INSTALLATION:

Step 1: Update Package Repository:

ubuntu@ip-172-31-36-149:~$ sudo apt-get update
Hit:1 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu jammy InRelease
Hit:2 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu jammy-updates InRelease
Hit:3 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu jammy-backports InRelease
Hit:4 http://security.ubuntu.com/ubuntu jammy-security InRelease
Reading package lists... Done
ubuntu@ip-172-31-36-149:~$

Step 2: Install Java: Jenkins requires Java to run. Install OpenJDK (Java Development Kit).

ubuntu@ip-172-31-36-149:~$ sudo apt-get install openjdk-11-jdk -y
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
openjdk-11-jdk is already the newest version (11.0.21+9-0ubuntu1~22.04).
0 upgraded, 0 newly installed, 0 to remove and 26 not upgraded.

ubuntu@ip-172-31-36-149:~$ java --version
openjdk 11.0.21 2023-10-17
OpenJDK Runtime Environment (build 11.0.21+9-post-Ubuntu-0ubuntu122.04)
OpenJDK 64-Bit Server VM (build 11.0.21+9-post-Ubuntu-0ubuntu122.04, mixed 
ubuntu@ip-172-31-36-149:~$

Step 3: Add Jenkins Repository Key: Add the Jenkins repository GPG key.

ubuntu@ip-172-31-36-149:~$ wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
OK
ubuntu@ip-172-31-36-149:~$

Step 4: Add Jenkins Repository: Add the Jenkins repository to your system.

ubuntu@ip-172-31-36-149:~$ sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
ubuntu@ip-172-31-36-149:~$

Step 5: Update Package Repository Again: Update the package repository to include the Jenkins repository.

ubuntu@ip-172-31-36-149:~$ sudo apt-get update

Step 6: Install Jenkins: Install Jenkins using the following command.

ubuntu@ip-172-31-36-149:~$ sudo apt install jenkins
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:

ubuntu@ip-172-31-36-149:~$ jenkins --version
2.426.2
ubuntu@ip-172-31-36-149:~$

Step 7: Start Jenkins Service: Start the Jenkins service.

ubuntu@ip-172-31-36-149:~$ sudo systemctl start jenkins

Step 8: Enable Jenkins Service to Start on Boot: Enable Jenkins to start on system boot.

ubuntu@ip-172-31-36-149:~$ sudo systemctl enable jenkins
Synchronizing state of jenkins.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable jenkins
ubuntu@ip-172-31-36-149:~$

Step 9: Check Jenkins Service Status: Check the status of the Jenkins service.

ubuntu@ip-172-31-36-149:~$ sudo systemctl status jenkins
โ— jenkins.service - Jenkins Continuous Integration Server
     Loaded: loaded (/lib/systemd/system/jenkins.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2023-12-24 07:49:57 UTC; 3min 48s ago
   Main PID: 7689 (java)

Step 10: Access Jenkins Web Interface: Open a web browser and navigate to http://your_server_ip_or_domain:8080.

  • You will be prompted to unlock Jenkins. Retrieve the initial password from the Jenkins server.
ubuntu@ip-172-31-36-149:~$ sudo cat /var/lib/jenkins/secrets/initialAdminPassword
11481ddd92ab4b2c906946c0276c5d5a
ubuntu@ip-172-31-36-149:~$
  • Paste the password into the Jenkins web interface to unlock.

Step 11: Complete Jenkins Setup: Follow the on-screen instructions to complete the Jenkins setup. This includes selecting recommended plugins, creating an admin user, and configuring Jenkins.

  1. selecting recommended plugins:

  2. creating an admin user:

JENKINS-HOMEPAGE:

That's it! Jenkins now successfully installed and running on our Ubuntu server.

Tasks:

1. What you understood in Jenkin, write a small article in your own words

Jenkins is an open-source solution comprising an automation server to enable (CI/CD), automating the various stages of software development such as build, test, and deployment.

Jenkins is a Java-based open-source platform with plugins designed for continuous integration. It is used to continually create and test software projects, making it easier for developers for changes to the project and for consumers to get a new build. It also enables you to release your software continuously by interacting with various testing and deployment methods.

2.Create a freestyle pipeline to print "Hello World!!

freestyle pipeline in Jenkins is a simple yet effective way to execute tasks in a sequential manner. Here's a step-by-step guide to creating a freestyle pipeline that prints "Hello World!!" when executed:

Step 1: Create a Freestyle Project:

  1. Click on "New Item" on the Jenkins homepage.

  2. Enter a name for your project, select "Freestyle project," and click "OK."

Step 2: Configure the Freestyle Project:

  1. In the project configuration page, under the "General" section, you can enter a description for your project if needed.

  2. Under the "Build" section, click on "Add build step" and select "Execute shell"

  3. In the command box, type the command to print "Hello World!!". For example:

  4. Click on "Save" to save your project configuration.

Step 3: Build the Freestyle Project:

  1. Go back to the Jenkins dashboard and find your newly created project.

  2. Click on your project, and on the left sidebar, click on "Build Now" to manually trigger the build.

  3. Jenkins will execute the build, and you can monitor the progress in the build history.

  4. Click on the build number to see the console output, and you should find "Hello World!!" printed as part of the build process.

Congratulations! We successfully created and executed a freestyle pipeline in Jenkins that prints "Hello World!!". This simple example lays the foundation for more complex pipelines involving multiple steps and integrations.

ย