JENKINS BASIC
⚙️ Jenkins – Complete Core Notes
CI/CD Pipeline Architecture, Declarative Jenkinsfile, Automated Builds, Plugins aur Master-Agent Ecosystem ka comprehensive guide.
1️⃣ Jenkins Kya Hai?
Definition: Jenkins ek leading open-source Java-based automation server hai jiska primary use software development me Continuous Integration (CI) aur Continuous Delivery/Deployment (CD) workflows ko automate karne ke liye kiya jata hai.
- CI (Continuous Integration): Developers ke code commit karte hi automatically code checkout, build compilation aur unit tests run karna.
- CD (Continuous Delivery/Deployment): Code tests pass hone ke baad binary artifacts ko automatically Staging ya Production servers par deploy karna.
- Automated Workflows: Manual deployments aur human errors ko eliminate karta hai.
- Vast Ecosystem: 1800+ community plugins ke sahare Git, Docker, Kubernetes, AWS aur Slack ke sath instantly connect hota hai.
- Web Interface: Browser-based intuitive UI provide karta hai jisse build status aur logs monitor karna aasan hota hai.
2️⃣ Jenkins Ke Core Features
- Pipeline-as-Code: Pura build aur deployment sequence code file (
Jenkinsfile) me store hota hai jo version control me track hoti hai. - Distributed Architecture: Master-Agent (Node) model ke sath builds ko multiple parallel servers par distribute kar sakta hai.
- Extensibility: Custom plugins ke sath kisi bhi programming language ya testing framework ko support karta hai.
- Easy Upgrades: Self-contained Java application hone ke karan single WAR package ya Docker container me easily deploy ho jata hai.
3️⃣ Installation & Initial Setup
- Prerequisite: Server par
Java (JDK 17 ya 21)install hona mandatory hai. - Download & Run: Official packages ya direct Docker container ke zariye start karein:
docker run -p 8080:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts - Access Dashboard: Browser me open karein:
http://localhost:8080 - Unlock Password: Terminal logs se initial admin password copy karke paste karein:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
4️⃣ Jenkins Jobs: Freestyle vs Pipeline
| Job Category | Configuration Style | Best Use-Case |
|---|---|---|
| Freestyle Project | Web UI forms aur dropdowns ke through configure hota hai. | Simple single-command tasks, batch scripts ya quick automated testing ke liye. |
| Pipeline (Declarative) | Jenkinsfile me code ke roop me likha jata hai. |
Complex multi-stage CI/CD deployments (Build → Test → Push → Deploy). |
5️⃣ Jenkins Declarative Pipeline (Jenkinsfile)
Industry-standard pipeline structure jisme har stage clear aur isolated hoti hai:
pipeline {
agent any // Kisi bhi available build agent par run karein
stages {
stage('Code Checkout') {
steps {
echo 'Checking out code from Git repository...'
}
}
stage('Build & Compile') {
steps {
echo 'Running build scripts (e.g., npm install / mvn clean package)...'
}
}
stage('Automated Testing') {
steps {
echo 'Executing unit and integration tests...'
}
}
stage('Production Deploy') {
steps {
echo 'Deploying artifact to AWS / Kubernetes cluster...'
}
}
}
post {
success {
echo 'Pipeline executed successfully! Notification sent.'
}
failure {
echo 'Build failed! Alert triggered to developer.'
}
}
}
6️⃣ Essential Production Plugins
| Plugin Name | Role in DevOps Pipeline |
|---|---|
| Git Plugin | GitHub, GitLab ya Bitbucket repos se automated webhooks aur checkout handle karta hai. |
| Docker Pipeline | Containers build karna aur Docker Hub / ECR par image push karne ka native support deta hai. |
| Pipeline Stage View | Dashboard par colorful visual blocks ke roop me stage progress display karta hai. |
| Slack / Email Extension | Build pass ya fail hone par teams ko instant notifications forward karta hai. |