Table of contents
Setting up a CI/CD (Continuous Integration/Continuous Delivery) pipeline using Jenkins can transform how you develop and deploy software. It helps automate repetitive tasks, improves code quality, and reduces deployment time. In this guide, we'll walk you through the steps to set up a Jenkins CI/CD pipeline, using simple language and plenty of emojis to make things fun! π
What is a CI/CD Pipeline? π€
A CI/CD pipeline is a series of automated steps that ensure your code is:
Built ποΈ
Tested β
Deployed π
It helps developers ship reliable and high-quality software quickly.
What is Jenkins?
Jenkins is an open-source automation server that makes building, testing, and deploying your projects simple. Think of it as your personal assistant for automating DevOps tasks. π€
Step 1: Install Jenkins π₯οΈ
Download Jenkins:
Go to the Jenkins website and download the latest version.Install Jenkins:
For Linux:
sudo apt update sudo apt install openjdk-11-jdk wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add - sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list' sudo apt update sudo apt install jenkins
For Windows/Mac: Use the installer provided on the Jenkins website.
Start Jenkins:
Access Jenkins athttp://localhost:8080
.
Step 2: Configure Jenkins βοΈ
Unlock Jenkins:
Copy the password from the file shown during the installation process.
Paste it into the browser.
Install Plugins:
Choose "Install suggested plugins" to get started quickly.Set Up Admin User:
Create an admin account to manage Jenkins.
Step 3: Create a New Pipeline π οΈ
Install Git Plugin:
Go to Manage Jenkins β Plugins and install the Git plugin.Create a Job:
Go to Dashboard β New Item.
Enter a name for your pipeline and select Pipeline.
Configure Pipeline:
In the Pipeline section, choose Pipeline script from SCM.
Add the Git repository URL where your code resides.
Step 4: Write a Jenkinsfile π
The Jenkinsfile defines the stages of your pipeline. Hereβs a basic example:
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building the application...'
sh './build.sh'
}
}
stage('Test') {
steps {
echo 'Running tests...'
sh './test.sh'
}
}
stage('Deploy') {
steps {
echo 'Deploying the application...'
sh './deploy.sh'
}
}
}
}
Step 5: Trigger the Pipeline π
Set Up Webhooks (Optional):
Connect Jenkins to your Git repository to trigger the pipeline automatically on code changes.Run the Pipeline:
Go to your job in Jenkins.
Click Build Now.
Monitor Progress:
Check the console output for real-time logs.
Fix any errors that may occur.
Step 6: Success! π
Congratulations, youβve set up a CI/CD pipeline using Jenkins! Now, every time you push code, Jenkins will:
Build your application ποΈ
Test it β
Deploy it π
Real-Life Example
Imagine youβre working on an e-commerce app. Whenever a developer pushes new features to GitHub:
Jenkins builds the app to check for issues.
It runs automated tests to ensure nothing is broken.
If everything passes, Jenkins deploys the app to your staging or production environment.
This ensures faster development cycles and higher-quality releases. π―
Benefits of Using Jenkins CI/CD Pipeline
Automation: No more manual deployments. ποΈ
Speed: Faster time-to-market. π
Reliability: Fewer errors, better code quality. β
Scalability: Jenkins works for small teams and large enterprises alike. π
Do you use Jenkins or any other CI/CD tool? Let me know in the comments!