Day-22 : Getting Started with Jenkins
What is Jenkins?
Jenkins is an open-source automation tool that helps developers and DevOps teams automate the process of building, testing, and deploying software.
It is widely used in DevOps to enable teams to deliver software faster and more efficiently by facilitating Continuous Integration (CI) and Continuous Delivery (CD).
Key Features of Jenkins :
Automation:
- Jenkins automates repetitive tasks like code building, testing, and deployment.
Continuous Integration (CI):
- It checks for new changes in the code (e.g., on GitHub), builds the code, and tests it automatically to ensure nothing is broken.
Continuous Delivery (CD):
- Jenkins can also deploy the software to a production or testing environment once the tests pass.
Plugins:
- Jenkins has hundreds of plugins to integrate with tools like Git, Docker, Kubernetes, AWS, and many more.
Easy Setup:
- It’s web-based, so you configure it from a simple interface.
How Does Jenkins Work?
A developer writes code and pushes it to a repository (like GitHub).
Jenkins detects this new code.
Jenkins automatically:
Pulls the code.
Builds it into a working program.
Runs automated tests to check for bugs.
Deploys it to a server or container (if all tests pass).
Why Use Jenkins?
Saves Time: Automates tasks that would take hours to do manually.
Improves Quality: Quickly catches errors with automated testing.
Speeds Up Releases: Helps deliver updates to users faster.
How to Use Jenkins?
Using Jenkins involves installing it, setting it up, and creating jobs or pipelines to automate various tasks in the software development lifecycle. Here's a step-by-step guide:
Installed Jenkins on Ubuntu server:
Prerequisites:
Install Jdk:
sudo apt-get update sudo apt-get install fontconfig openjdk-17-jre java --version
Ensure the server has enough memory (at least 1 GB).
Install Jenkins:
Access Jenkins: Open your browser and navigate to:
http://<your-server-ip>:8080
.Unlock Jenkins using the password found in:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Complete Setup:
Install recommended plugins.
Create an admin user account.
Jenkins is ready to use:-
Tasks:-
Create a Freestyle Pipeline to Print "Hello World"
Log in to Jenkins.
On the Jenkins dashboard, click on "New Item".
Enter a name for your job, e.g.,
Hello-World
.Select "Pipeline" from the list of options and click "OK".
Scroll down to the Pipeline section.
Select Pipeline script (default option).
Enter the following basic pipeline code:
pipeline { agent any stages { stage('Demo') { steps { echo 'Hello World' } } } }
Run the Pipeline
On the job's main page, click "Build Now".
Go to the "Build History" section on the left and click on the latest build.
Click "Console Output" to see the result. You should see:
Create a freestyle pipeline in Jenkins that prints the current date and time:
pipeline{
agent any
stages{
stage("Print-date"){
steps{
sh "date"
}
}
}
}
Output:
Subscribe to my newsletter
Read articles from Anjali Kashyap directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by