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:
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.
Note: By now Jenkins should be installed on your machine(as it was a part of previous tasks, if not follow Installation Guide)
Task 1: Article on Jenkins and Its Role in DevOps
Jenkins: An Overview
Jenkins is an open-source automation server that plays a vital role in modern DevOps practices by enabling Continuous Integration and Continuous Delivery (CI/CD). It’s a widely adopted tool that helps teams streamline their software development lifecycle, from code integration to testing and deployment. Jenkins is developed in Java and provides flexibility through an extensive array of plugins that can be tailored to fit various DevOps stages like version control, build, testing, and deployment.
Why Jenkins is Essential in DevOps
In the fast-paced world of software development, automation has become essential. Jenkins allows development teams to automate repetitive tasks, reducing manual intervention and freeing up time for more strategic work. Jenkins can handle everything from basic tasks like code compilation and testing to complex, multi-step deployment processes, ensuring smoother and faster releases.
How Jenkins Integrates into the DevOps Lifecycle
Jenkins fits seamlessly into the DevOps pipeline by integrating with other tools to handle different stages of development and deployment. Jenkins can work with Git for version control, Docker for containerization, and a variety of testing tools to automate and manage the entire workflow. This automation not only saves time but also reduces human error, improving the quality and consistency of software releases.
Benefits of Jenkins in Build, Test, and Deployment Automation
Build Automation: Jenkins compiles code from different branches and merges it, ensuring that the latest code is always integrated without any conflicts. This results in faster and more efficient builds.
Testing: Automated testing can be configured to run at each stage, verifying the code’s integrity before moving to the next step. Jenkins helps in integrating various testing tools, so issues are caught early on.
Deployment: Jenkins can deploy code to different environments automatically, whether it's for staging or production, using triggers and schedules. This removes the need for manual deployment steps, which can be time-consuming and error-prone.
In summary, Jenkins provides a reliable solution for automating repetitive tasks in software development, making it easier to manage, test, and deploy code in a continuous, integrated manner.
Task 2: Creating a Freestyle Pipeline in Jenkins
To create a basic Jenkins pipeline, follow these steps:
Create the Freestyle Pipeline:
Open Jenkins and go to New Item.
Choose Freestyle Project and name it, e.g., "HelloWorldPipeline."
Pipeline Steps:
In the Build section, add a Build Step for Execute Shell.
Add the following script to print "Hello World" and the current date and time:
echo "Hello World" date
Cloning a GitHub Repository:
Add another Build Step for Execute Shell.
Use the following script to clone a repository and list its contents:
git clone https://github.com/yourusername/your-repository.git ls your-repository
Replace
https://github.com/yourusername/your-repository.git
with your actual repository URL.
Set Periodic Trigger:
Go to the Build Triggers section.
Select Build periodically and enter
H * * * *
to set it to run every hour.
Save and Run:
Click Save to save the pipeline.
Click Build Now to test it.
This setup will run the pipeline every hour, printing "Hello World," displaying the current date and time, cloning the specified GitHub repository, and listing its contents. By following these steps, you've successfully created a simple Jenkins pipeline that demonstrates basic automation.
#HappyLearning
Subscribe to my newsletter
Read articles from Faizan Shaikh directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by