Day 22: Getting Started with Jenkins π

Greetings! π I'm Priyadarshi Ranjan, a dedicated DevOps Engineer embarking on an enriching journey. Join me as I delve into the dynamic realms of cloud computing and DevOps through insightful blogs and updates. π οΈ My focus? Harnessing AWS services, optimizing CI/CD pipelines, and mastering infrastructure as code. Whether you're peers, interns, or curious learners, let's thrive together in the vibrant DevOps ecosystem. π Connect with me for engaging discussions, shared insights, and mutual growth opportunities. Let's embrace the learning curve and excel in the dynamic realm of AWS and DevOps technology!
Introduction to Jenkins
What is Jenkins?
Jenkins is an open-source automation tool written in Java. It helps developers and DevOps teams to build, test, and deploy software quickly and efficiently. Jenkins uses plugins to integrate with various tools and services, making it highly customizable to suit different needs.
Master-Slave Architecture of Jenkins
Jenkins uses a master-slave architecture. The master node distributes tasks to the slave nodes, which then execute these tasks based on the masterβs instructions. This setup allows for efficient workload distribution and faster processing.

Features of Jenkins
Easy Installation: Jenkins is a Java-based program that can run on Windows, Mac OS, and Unix-like systems. Itβs easy to install and set up.
Easy Configuration: Jenkins can be configured using its web interface, which includes helpful error checks and built-in help functions.
Available Plugins: Jenkins has hundreds of plugins that integrate with various tools in the CI/CD pipeline.
Extensible: The plugin architecture allows Jenkins to be extended to suit almost any need.
Easy Distribution: Jenkins can distribute work across multiple machines to speed up builds, tests, and deployments.
Free and Open Source: Jenkins is free to use and has strong community support.
What is a Pipeline in Jenkins?
A pipeline is a sequence of tasks or events that automate the software release process. For example, a pipeline can build code, run tests, and deploy new software versions in a defined order. Pipelines in Jenkins help streamline and automate these processes, making them faster and more reliable.
What is CI/CD in Jenkins?
CI/CD stands for Continuous Integration and Continuous Delivery (or Deployment). It is a set of practices used in software development to deliver software quickly and reliably.
Continuous Integration (CI): This practice integrates code changes from multiple developers into a shared repository. Automated builds and tests are triggered whenever changes are pushed, ensuring quick feedback on code quality.
Continuous Delivery (CD): This practice ensures that code changes are ready to be deployed at any time. Jenkins automates the deployment process to various environments, ensuring consistent and reliable releases.
Continuous Deployment: This extends Continuous Delivery by automatically deploying changes to production as soon as they pass tests.
Use Cases of Jenkins
Automated Testing: Jenkins can run automated tests to identify bugs and issues early in the development cycle.
Deployment Orchestration: Jenkins can automate the deployment of applications to different servers and environments.
Scheduled Jobs and Batch Processing: Jenkins can run routine tasks like backups, generating reports, or executing batch jobs at scheduled times.
What is a Project in Jenkins?
Jenkins uses projects (also known as jobs) to perform tasks. There are different types of projects in Jenkins, including Freestyle, Pipeline, Multibranch Pipeline, and others.
Different Types of Jenkins Projects:
Freestyle Project: This is a basic project type that allows flexible configurations and build steps. Itβs suitable for simple build processes.
Pipeline Project: This allows defining the build, test, and deployment workflows as code. Pipelines are highly versatile and scalable.
Multibranch Pipeline: This project type is useful for managing multiple branches in your source code repository, with each branch having its own build pipeline.
Setting Up Jenkins
Prerequisites:
Minimum hardware requirements:
256 MB of RAM
1 GB of drive space (10 GB recommended if running Jenkins as a Docker container)
Java 11 or 17 is required.
Installing Jenkins:
Update Packages:
sudo apt-get updateInstall Java:
sudo apt install openjdk-11-jreCheck Java Installation:
java --versionAdd Jenkins Repository Key:
curl -fsSL https://pkg.jenkins.io/debian/jenkins.io-2023.key | sudo tee /usr/share/keyrings/jenkins-keyring.asc > /dev/nullAdd Jenkins Repository:
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian binary/ | sudo tee /etc/apt/sources.list.d/jenkins.list > /dev/nullUpdate Package Lists and Install Jenkins:
sudo apt-get update sudo apt-get install jenkinsStart Jenkins:
sudo systemctl start jenkinsCheck Jenkins Status:
systemctl status jenkins
Open Port 8080: Ensure that port 8080 is open in your security group settings.

Access Jenkins Web Interface: Open a web browser and enter the public IP address or DNS name of your EC2 instance followed by
:8080(e.g.,http://<your_public_ip>:8080).
Find Admin Password: The admin password is located in the file path provided by Jenkins during setup.

Customize Jenkins: Install suggested plugins and create the first admin user.




Congratulations! You have successfully installed Jenkins on your server and accessed the Jenkins web interface.

Task 1: Create a Freestyle Pipeline to Print "Hello World!"
Create a New Job:
Click on "New Item" to create a new Jenkins job.

Enter the name "HelloWorldPipeline" and select "Freestyle project", then click "OK".

Configure the Job:
Scroll down to the "Build" section.

Click on "Add build step" and select "Execute shell".

Add the Script:
In the command box, enter:
echo "Hello World"
Save and Build:
Click "Save" to save the configuration.
On the project page, click "Build Now" to run the job.

View the Output:
Click on the build number in the "Build History".

Click on "Console Output" to see the result. You should see "Hello World" printed in the output.

Conclusion
Jenkins is a powerful tool that automates the software development process, making it faster and more reliable. By setting up Jenkins and creating pipelines, you can streamline your build, test, and deployment workflows, ensuring efficient and error-free software delivery.
In this post, we introduced Jenkins, its features, and how to set it up. We also created a simple pipeline to print "Hello World!" Stay tuned for more advanced topics and use cases of Jenkins in upcoming posts. Happy coding! π
Connect and Follow Me on Socials




