π JENKINS FULL END-TO-END TUTORIAL¶
π§± 1. What is Jenkins?¶
Jenkins is an open-source automation server used to:
-
Build and test your code continuously (CI)
-
Deploy applications automatically (CD)
-
Orchestrate DevOps pipelines (with Docker, Kubernetes, etc.)
It supports plugins for everything β GitHub, Docker, SonarQube, AWS, ArgoCD, etc.
π§° 2. System Requirements¶
| Requirement | Recommended |
|---|---|
| OS | Ubuntu 20.04 / 22.04 (or Windows) |
| RAM | 4 GB minimum |
| Java | Java 11+ (JDK 17 preferred) |
| Browser | Chrome / Firefox |
βοΈ 3. Jenkins Installation (Ubuntu)¶
Step 1: Update packages¶
Step 2: Install Java¶
Step 3: Add Jenkins repository and key¶
curl -fsSL https://pkg.jenkins.io/debian/jenkins.io.key | sudo tee \
/usr/share/keyrings/jenkins-keyring.asc > /dev/null
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/null
Step 4: Install Jenkins¶
Step 5: Start Jenkins¶
Step 6: Access Jenkins¶
Go to β
π http://localhost:8080
Get the initial admin password:
π§© 4. Setup Wizard¶
-
Paste the admin password.
-
Choose βInstall suggested pluginsβ.
-
Create your admin user.
-
Youβll land on the Jenkins Dashboard.
π§± 5. Jenkins Architecture Overview¶
Key Components:¶
| Component | Description |
|---|---|
| Jenkins Master | Orchestrates builds and manages agents |
| Agent/Node | Executes the actual build steps |
| Pipeline | Script that defines your CI/CD flow |
| Job | Unit of work (can be Freestyle or Pipeline) |
| Workspace | Directory on agent where build happens |
π§© 6. Jenkins Plugins (Essential Ones)¶
Go to: Manage Jenkins β Plugins β Available
Search & Install:
β
Git
β
Docker
β
Pipeline
β
Blue Ocean (modern UI)
β
Kubernetes
β
Snyk Security (optional)
ποΈ 7. Example Project: CI/CD Pipeline for a Python Web App¶
Letβs say your repo structure is:
Step 1: Dockerfile¶
FROM python:3.11-slim
WORKDIR /app
COPY . /app
RUN pip install -r requirements.txt
CMD ["python", "app.py"]
Step 2: Jenkins Pipeline (Jenkinsfile)¶
Create a file named Jenkinsfile in your repo:
pipeline {
agent any
environment {
DOCKER_HUB_USER = credentials('dockerhub-credentials')
IMAGE_NAME = "yuvaraj/my-app"
}
stages {
stage('Checkout Code') {
steps {
git branch: 'main', url: 'https://github.com/yuvaraj/my-app.git'
}
}
stage('Install Dependencies') {
steps {
sh 'pip install -r requirements.txt'
}
}
stage('Run Tests') {
steps {
sh 'pytest || echo "Tests Skipped"'
}
}
stage('Build Docker Image') {
steps {
script {
sh "docker build -t $IMAGE_NAME:${env.BUILD_NUMBER} ."
}
}
}
stage('Push to Docker Hub') {
steps {
script {
sh "echo $DOCKER_HUB_USER_PSW | docker login -u $DOCKER_HUB_USER_USR --password-stdin"
sh "docker push $IMAGE_NAME:${env.BUILD_NUMBER}"
}
}
}
stage('Deploy to Kubernetes') {
steps {
script {
sh 'kubectl apply -f k8s/deployment.yaml'
}
}
}
}
post {
always {
echo "Pipeline finished: ${currentBuild.currentResult}"
}
}
}
Step 3: Create Jenkins Credentials¶
Go to:
Manage Jenkins β Credentials β Global β Add Credentials
Add:
-
Docker Hub Username/Password
-
Kubernetes Kubeconfig (if youβre deploying to a cluster)
Step 4: Create Pipeline Job¶
-
Go to Jenkins Dashboard
-
Click βNew Itemβ β Pipeline
-
Name:
my-app-pipeline -
Under Pipeline β Choose Pipeline script from SCM
-
Select Git, paste repo URL, branch =
main -
Save & Run β
Step 5: Watch Pipeline in Action¶
Youβll see stages like:
[1] Checkout Code
[2] Install Dependencies
[3] Run Tests
[4] Build Docker Image
[5] Push to Docker Hub
[6] Deploy to Kubernetes
If all succeed β Jenkins deploys automatically π
π§ 8. Jenkins Pipeline Types¶
| Type | Description |
|---|---|
| Declarative Pipeline | Easier syntax (recommended for beginners) |
| Scripted Pipeline | Fully Groovy-based, more flexible |
Example:
π 9. Integrations¶
| Tool | Integration |
|---|---|
| GitHub Webhook | Auto-trigger Jenkins when new code is pushed |
| Slack | Send build notifications |
| SonarQube | Code quality analysis |
| Trivy / Snyk | Container security scanning |
| AWS / GCP | Deploy using Jenkins pipelines |
π 10. Jenkins + GitHub Webhook Setup¶
1. Go to your GitHub repo β Settings β Webhooks β Add webhook¶
-
Payload URL:
http://<your-server-ip>:8080/github-webhook/ -
Content type:
application/json -
Trigger: βJust the push eventβ
Now every push triggers Jenkins automatically π
π§© 11. Jenkins + Docker Integration¶
Install Docker plugin and ensure Jenkins user can run Docker:
Verify inside Jenkins:
π§ 12. Jenkins + Kubernetes (Optional)¶
If you have Kubernetes (like Minikube or AWS EKS):
-
Create
k8s/deployment.yaml -
Use Jenkins
kubectl apply -fstep -
You can even run Jenkins inside Kubernetes with a Helm chart.
πͺΆ 13. Monitoring Jenkins¶
-
URL:
http://localhost:8080/monitoring -
Integrate Prometheus plugin
-
View build metrics and job status in Grafana dashboards.
π§© 14. Best Practices¶
β
Store pipeline code in Jenkinsfile (GitOps-style).
β
Use credentials from Jenkins Secret Store.
β
Keep stages modular: build, test, deploy, notify.
β
Use Docker agents for isolated builds.
β
Enable security: disable anonymous access.
β
Use backup plugin or external volume for /var/lib/jenkins.
β‘ 15. Sample Real-World Flow¶
Developer β Git Push β
GitHub Webhook triggers Jenkins β
Build + Test β
Docker Image β
Push to Docker Hub β
Deploy to Kubernetes β
Prometheus + Grafana monitor app β
Slack notification sent.