Master continuous integration and deployment with the world's leading automation server
Jenkins is an open-source automation server that enables developers to build, test, and deploy their software reliably. As the most popular CI/CD tool, Jenkins automates the software development lifecycle and facilitates continuous integration and continuous delivery.
Continuous Integration (CI) is the practice of automatically building and testing code every time a team member commits changes to version control.
Continuous Delivery/Deployment (CD) extends CI by automatically deploying all code changes to a testing or production environment after the build stage.
Completely free to use with no licensing costs. Large community support and active development.
Over 1,800 plugins available for integrating with virtually any tool in your DevOps toolchain.
Written in Java, runs on Windows, Mac, Linux, and Unix systems. Supports all major version control systems.
Define your entire build/test/deploy pipeline in a Jenkinsfile stored with your source code.
Scale horizontally by distributing builds across multiple machines for faster execution.
Trusted by thousands of organizations worldwide, from startups to Fortune 500 companies.
| Feature | Jenkins | GitLab CI | GitHub Actions | CircleCI |
|---|---|---|---|---|
| Cost | Free (self-hosted) | Free tier + paid | Free tier + paid | Free tier + paid |
| Plugins | 1,800+ | Limited | Marketplace | Orbs |
| Hosting | Self-hosted | Cloud or self-hosted | Cloud only | Cloud or self-hosted |
| Setup Complexity | Moderate | Easy | Very Easy | Easy |
Jenkins follows a master-agent (formerly master-slave) architecture:
Jenkins Master
│
├── Agent 1 (Linux) → Runs Java builds
├── Agent 2 (Windows) → Runs .NET builds
├── Agent 3 (macOS) → Runs iOS builds
└── Agent 4 (Docker) → Runs containerized builds
# Pull and run Jenkins in Docker
docker run -d -p 8080:8080 -p 50000:50000 \
--name jenkins \
-v jenkins_home:/var/jenkins_home \
jenkins/jenkins:lts
# Get initial admin password
docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword
# Add Jenkins repository
curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.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-stable binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list > /dev/null
# Install Jenkins
sudo apt update
sudo apt install jenkins
# Start Jenkins
sudo systemctl start jenkins
sudo systemctl enable jenkins
Download the Windows installer from jenkins.io and follow the installation wizard.
http://localhost:8080/var/jenkins_home/secrets/initialAdminPasswordThe simplest job type. Good for simple tasks but less flexible than pipelines.
Define your entire CI/CD process as code. Most flexible and powerful.
Automatically creates pipelines for each branch in your repository.
Scans an entire GitHub/Bitbucket organization for repositories with Jenkinsfiles.
Jenkins Pipeline allows you to define your build process as code in a Jenkinsfile.
pipeline {
agent any
environment {
APP_NAME = 'my-app'
VERSION = '1.0.0'
}
stages {
stage('Checkout') {
steps {
git branch: 'main',
url: 'https://github.com/user/repo.git'
}
}
stage('Build') {
steps {
sh 'npm install'
sh 'npm run build'
}
}
stage('Test') {
steps {
sh 'npm test'
}
}
stage('Deploy') {
when {
branch 'main'
}
steps {
sh './deploy.sh'
}
}
}
post {
success {
echo 'Pipeline succeeded!'
mail to: 'team@example.com',
subject: "Build Successful: ${env.JOB_NAME}",
body: "Good news! Build ${env.BUILD_NUMBER} succeeded."
}
failure {
echo 'Pipeline failed!'
mail to: 'team@example.com',
subject: "Build Failed: ${env.JOB_NAME}",
body: "Build ${env.BUILD_NUMBER} failed. Please investigate."
}
}
}
node {
stage('Checkout') {
checkout scm
}
stage('Build') {
try {
sh 'make build'
} catch (Exception e) {
echo "Build failed: ${e.getMessage()}"
throw e
}
}
stage('Test') {
parallel(
'Unit Tests': {
sh 'npm run test:unit'
},
'Integration Tests': {
sh 'npm run test:integration'
}
)
}
stage('Deploy') {
if (env.BRANCH_NAME == 'main') {
sh 'kubectl apply -f deployment.yaml'
}
}
}
Jenkins' power comes from its extensive plugin ecosystem.
# In GitHub repository settings:
# 1. Go to Settings → Webhooks → Add webhook
# 2. Payload URL: http://your-jenkins-url/github-webhook/
# 3. Content type: application/json
# 4. Events: Push events, Pull request events
// Jenkinsfile in repository root
pipeline {
agent any
stages {
stage('Build PR') {
when {
changeRequest()
}
steps {
echo "Building PR #${env.CHANGE_ID}"
sh 'npm install && npm run build'
}
}
stage('Deploy Main') {
when {
branch 'main'
}
steps {
echo "Deploying main branch"
sh './deploy.sh production'
}
}
}
}
Install the GitLab Plugin and configure webhooks similarly to GitHub.
Use Bitbucket Branch Source Plugin for Bitbucket Cloud/Server integration.
stage('Unit Tests') {
steps {
sh 'npm test'
junit 'test-results/*.xml' // Publish test results
}
}
stage('Integration Tests') {
steps {
// Start test environment
sh 'docker-compose up -d'
// Run tests
sh 'npm run test:integration'
// Cleanup
sh 'docker-compose down'
}
}
stage('Code Coverage') {
steps {
sh 'npm run coverage'
publishHTML target: [
reportDir: 'coverage',
reportFiles: 'index.html',
reportName: 'Coverage Report'
]
}
}
stage('Build Docker Image') {
steps {
script {
docker.build("myapp:${env.BUILD_NUMBER}")
}
}
}
stage('Push to Registry') {
steps {
script {
docker.withRegistry('https://registry.example.com', 'docker-credentials') {
docker.image("myapp:${env.BUILD_NUMBER}").push()
docker.image("myapp:${env.BUILD_NUMBER}").push('latest')
}
}
}
}
stage('Deploy to Kubernetes') {
steps {
script {
kubernetesDeploy(
configs: 'k8s/*.yaml',
kubeconfigId: 'kubeconfig-credentials',
enableConfigSubstitution: true
)
}
}
}
stage('Blue-Green Deploy') {
steps {
// Deploy to green environment
sh 'kubectl apply -f green-deployment.yaml'
// Wait for health check
sh 'kubectl wait --for=condition=ready pod -l app=green'
// Switch traffic to green
sh 'kubectl patch service myapp -p \'{"spec":{"selector":{"version":"green"}}}\''
// Cleanup blue environment
sh 'kubectl delete deployment blue'
}
}
Fine-grained permissions per user or group for specific projects.
Define roles with specific permissions and assign users to roles.
// Using credentials in Pipeline
pipeline {
agent any
stages {
stage('Deploy') {
steps {
withCredentials([
usernamePassword(
credentialsId: 'aws-credentials',
usernameVariable: 'AWS_ACCESS_KEY',
passwordVariable: 'AWS_SECRET_KEY'
)
]) {
sh 'aws s3 sync build/ s3://my-bucket/'
}
}
}
}
}
-Xmx4g// Enable debug output
pipeline {
agent any
options {
timestamps()
timeout(time: 1, unit: 'HOURS')
}
stages {
stage('Debug') {
steps {
echo "Branch: ${env.BRANCH_NAME}"
echo "Build Number: ${env.BUILD_NUMBER}"
sh 'env | sort' // Print all environment variables
}
}
}
}