It helps developers automate parts of the software development process such as building, testing, and deploying code.
Continuous Integration (CI):
Automatically builds and tests code whenever developers commit changes.
Ensures new code integrates smoothly with the existing codebase.
Continuous Delivery (CD):
Automates deployment pipelines so new versions can be delivered to staging or production environments with minimal manual effort.
Pipeline as Code:
Pipelines are defined in a file called Jenkinsfile using a Groovy-based DSL (Domain Specific Language).
Makes CI/CD pipelines version-controlled and reproducible.
Extensibility:
Jenkins supports over 1,800 plugins, allowing integration with nearly any tool in the development ecosystem (e.g., GitHub, Docker, Kubernetes, Maven, Slack).
Distributed Builds:
Can run tasks across multiple machines (called agents) for scalability and efficiency.
Source Code Management (SCM): Jenkins connects to code repositories like GitHub, GitLab, or Bitbucket.
Triggers: Jobs can start automatically (e.g., after a commit, at a set time, or by a webhook).
Build Execution: Jenkins runs the defined steps — compiling code, running tests, packaging artifacts.
Reports & Notifications: It reports results and can send notifications via email, Slack, or other tools.
Deployment: Can automatically deploy applications to servers or cloud environments.
Handles:
Scheduling jobs
Monitoring agents
Managing build pipelines
Serving the web UI and API
The controller distributes work to one or more agents.
Each agent can run different environments or tools.
Each agent has one or more executors, meaning how many builds it can run simultaneously.
Agents connect to the controller via:
SSH
JNLP (Java Network Launch Protocol)
or other protocols.
Developer pushes code to GitHub/GitLab → Jenkins is triggered (via webhook).
Jenkins Controller assigns the job to an Agent with Maven.
Maven compiles code and packages the app (e.g., .jar, .war).
JUnit / Selenium runs automated tests.
SonarQube analyzes code quality and security.
Jenkins builds a Docker image and pushes it to Docker Hub or Artifactory.
Jenkins deploys the image to Kubernetes, AWS ECS, or another environment.
Metrics sent to Prometheus/Grafana for health checks.
Slack or Email notifications alert the team of build/deploy results.
Install Jenkins (on your local machine, VM, or server).
Access Jenkins at http://localhost:8080 (by default).
Complete the initial setup wizard.
Install recommended plugins (including Git, Maven, Docker, Kubernetes plugins, etc.).
Create an admin user.
Then, connect Jenkins to the external tools → so Jenkins now knows how to use those tools when the pipeline (defined in Jenkinsfile file) asks for them.
Git (Source code version control) → Configure repository URL or credentials in Jenkins
Maven (Build Java projects) → Add Maven installation under Manage Jenkins → Global Tool Configuration Build Java projects
Docker (Build & push container images) → Install Docker plugin & connect to Docker host
Kubernetes (Deploy containers) → Install K8s plugin & configure cluster credentials
SonarQube, Slack, etc. (Code quality & notifications) → Add plugins or credentials as needed
A Jenkinsfile is a text file that defines the entire CI/CD pipeline as code.
It tells Jenkins what to do, step-by-step, from building to testing to deploying the application.
my-project/
├── src/
├── pom.xml
└── Jenkinsfile
Here’s a simple example (written in Groovy syntax):
pipeline {
agent any
environment {
DOCKER_IMAGE = "my-app:latest"
K8S_NAMESPACE = "default"
DEPLOY_USER = "user"
DEPLOY_SERVER = "server"
DEPLOY_PATH = "/deploy/path/"
}
stages {
stage('Build') {
steps {
echo 'Building Maven project...'
sh 'mvn clean package'
}
}
stage('Test') {
steps {
echo 'Running unit tests...'
sh 'mvn test'
}
}
stage('Deploy to Server') {
steps {
echo 'Deploying JAR to remote server...'
sh "scp target/myapp.jar $DEPLOY_USER@$DEPLOY_SERVER:$DEPLOY_PATH"
}
}
stage('Docker Build & Push') {
steps {
echo 'Building Docker image...'
sh "docker build -t $DOCKER_IMAGE ."
// Uncomment below if you have a Docker registry
// sh "docker push myregistry/$DOCKER_IMAGE"
}
}
stage('Deploy to Kubernetes') {
steps {
echo 'Deploying to Kubernetes...'
sh "kubectl apply -f k8s/deployment.yaml -n $K8S_NAMESPACE"
sh "kubectl apply -f k8s/service.yaml -n $K8S_NAMESPACE"
}
}
}
post {
success {
echo 'Pipeline completed successfully!'
}
failure {
echo 'Pipeline failed. Check logs for details.'
}
}
}
Breakdown:
pipeline { ... } → Defines the start of the pipeline.
agent any → Means Jenkins can run this pipeline on any available agent.
stages { ... } → Defines multiple stages (like Build, Test, Deploy).
steps { ... } → Contains the commands to execute inside each stage.
Go to New Item → Pipeline → Pipeline from SCM.
Link it to the Git repository containing the Jenkinsfile.
Jenkins automatically reads and executes the pipeline defined in the file.
From now on:
Every time we push code to the Git repo,
Jenkins automatically detects the change,
And executes the Jenkinsfile pipeline (build, test, deploy, etc.).
Integrating Maven, Docker, Kubernetes, and a Jenkinsfile for CI/CD.
my-app/
├── Jenkinsfile ← Pipeline definition for Jenkins
├── pom.xml ← Maven project file (build & dependencies)
├── src/ ← Java source code
│ ├── main/
│ │ └── java/
│ │ └── com/example/App.java
│ └── test/
│ └── java/
│ └── com/example/AppTest.java
├── Dockerfile ← Docker instructions for building image
├── k8s/
│ ├── deployment.yaml ← Kubernetes Deployment config
│ └── service.yaml ← Kubernetes Service config
└── README.md