Jenkins – Open Source Automation Server for CI/CD

4.7 Stars
Version 2.426
100 MB
Jenkins – Open Source Automation Server for CI/CD

What is Jenkins?

Jenkins is the leading open-source automation server that enables developers to build, test, and deploy software reliably and continuously. Originally developed as Hudson by Kohsuke Kawaguchi at Sun Microsystems, Jenkins has evolved into the most widely adopted continuous integration and continuous delivery (CI/CD) tool in the software industry.

With over 1,800 plugins available, Jenkins integrates with virtually every tool in the DevOps ecosystem, from source control systems like Git to deployment platforms like Kubernetes. Its extensible architecture, combined with Pipeline as Code capabilities, makes Jenkins adaptable to any workflow regardless of complexity.

Organizations worldwide rely on Jenkins to automate repetitive tasks, enforce quality gates, and accelerate software delivery. Whether building a simple project or orchestrating complex deployment pipelines across multiple environments, Jenkins provides the flexibility and power to automate the entire software development lifecycle.

Key Features and Capabilities

Pipeline as Code

Jenkins Pipeline enables defining entire build processes as code using either Declarative or Scripted Pipeline syntax. Pipelines are version-controlled alongside application code, enabling review, auditing, and evolution of build processes. The Jenkinsfile defines stages, steps, and conditions for complete build automation.

Distributed Builds

Jenkins supports distributed builds across multiple machines through its agent architecture. A controller node coordinates builds while agent nodes execute jobs, enabling horizontal scaling and specialized build environments. Agents can run on physical machines, VMs, or containers.

Extensive Plugin Ecosystem

The Jenkins plugin ecosystem provides integrations with source control (Git, SVN), build tools (Maven, Gradle), testing frameworks, deployment platforms, notification systems, and cloud providers. Plugins extend core functionality without modifying Jenkins itself.

Build Triggers

Multiple trigger mechanisms initiate builds: webhooks from source control, scheduled execution (cron), upstream job completion, and manual triggering. Poll SCM provides fallback when webhooks aren’t available.

Credential Management

Jenkins securely stores and manages credentials including passwords, SSH keys, certificates, and API tokens. Credentials integrate with pipelines while keeping sensitive data encrypted and access-controlled.

System Requirements

Hardware Requirements

Jenkins controller requires minimum 256 MB RAM, though 1 GB+ is recommended for production. Java 11 or Java 17 runtime is required. Disk space depends on build artifacts and job history retention. Build agents should be sized according to workload requirements.

Supported Platforms

Jenkins runs on any platform supporting Java: Windows, macOS, Linux, and various Unix systems. Docker images provide consistent deployment across environments. Kubernetes deployments enable dynamic scaling.

Installation Guide

Installing on Ubuntu/Debian

# Install Java
sudo apt update
sudo apt install fontconfig openjdk-17-jre

# Add Jenkins repository
sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
  https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
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 enable jenkins
sudo systemctl start jenkins

# Get initial admin password
sudo cat /var/lib/jenkins/secrets/initialAdminPassword

# Access at http://localhost:8080

Installing on RHEL/CentOS

# Install Java
sudo dnf install java-17-openjdk

# Add Jenkins repository
sudo wget -O /etc/yum.repos.d/jenkins.repo \
  https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key

# Install Jenkins
sudo dnf install jenkins

# Start Jenkins
sudo systemctl enable jenkins
sudo systemctl start jenkins

# Configure firewall
sudo firewall-cmd --permanent --add-port=8080/tcp
sudo firewall-cmd --reload

Installing with Docker

# Run Jenkins container
docker run -d \
  --name jenkins \
  -p 8080:8080 \
  -p 50000:50000 \
  -v jenkins_home:/var/jenkins_home \
  jenkins/jenkins:lts

# Get initial password
docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword

# Docker Compose
version: '3.8'
services:
  jenkins:
    image: jenkins/jenkins:lts
    privileged: true
    user: root
    ports:
      - "8080:8080"
      - "50000:50000"
    volumes:
      - jenkins_home:/var/jenkins_home
      - /var/run/docker.sock:/var/run/docker.sock
volumes:
  jenkins_home:

Installing on Kubernetes

# Using Helm
helm repo add jenkins https://charts.jenkins.io
helm repo update

# Install with default values
helm install jenkins jenkins/jenkins

# Get admin password
kubectl exec --namespace default -it svc/jenkins -c jenkins -- /bin/cat /run/secrets/additional/chart-admin-password

# Custom values.yaml
controller:
  adminPassword: "your-password"
  installPlugins:
    - kubernetes
    - workflow-aggregator
    - git
    - configuration-as-code
  resources:
    requests:
      cpu: "500m"
      memory: "1Gi"
    limits:
      cpu: "2000m"
      memory: "4Gi"

Pipeline Syntax

Declarative Pipeline

// Jenkinsfile
pipeline {
    agent any
    
    environment {
        APP_NAME = 'my-application'
        VERSION = '1.0.0'
        DOCKER_REGISTRY = 'registry.example.com'
    }
    
    options {
        timeout(time: 1, unit: 'HOURS')
        disableConcurrentBuilds()
        buildDiscarder(logRotator(numToKeepStr: '10'))
    }
    
    stages {
        stage('Checkout') {
            steps {
                checkout scm
            }
        }
        
        stage('Build') {
            steps {
                sh 'mvn clean package -DskipTests'
            }
        }
        
        stage('Test') {
            parallel {
                stage('Unit Tests') {
                    steps {
                        sh 'mvn test'
                    }
                }
                stage('Integration Tests') {
                    steps {
                        sh 'mvn verify -Pintegration'
                    }
                }
            }
        }
        
        stage('Code Analysis') {
            steps {
                withSonarQubeEnv('SonarQube') {
                    sh 'mvn sonar:sonar'
                }
            }
        }
        
        stage('Build Docker Image') {
            steps {
                script {
                    docker.build("${DOCKER_REGISTRY}/${APP_NAME}:${VERSION}")
                }
            }
        }
        
        stage('Deploy to Staging') {
            when {
                branch 'develop'
            }
            steps {
                sh 'kubectl apply -f k8s/staging/'
            }
        }
        
        stage('Deploy to Production') {
            when {
                branch 'main'
            }
            input {
                message "Deploy to production?"
                ok "Deploy"
            }
            steps {
                sh 'kubectl apply -f k8s/production/'
            }
        }
    }
    
    post {
        always {
            junit '**/target/surefire-reports/*.xml'
            archiveArtifacts artifacts: 'target/*.jar'
        }
        success {
            slackSend channel: '#builds', 
                      color: 'good', 
                      message: "Build Successful: ${env.JOB_NAME} #${env.BUILD_NUMBER}"
        }
        failure {
            slackSend channel: '#builds', 
                      color: 'danger', 
                      message: "Build Failed: ${env.JOB_NAME} #${env.BUILD_NUMBER}"
        }
    }
}

Scripted Pipeline

// Scripted Pipeline example
node {
    def mvnHome = tool 'Maven-3.9'
    
    stage('Checkout') {
        checkout scm
    }
    
    stage('Build') {
        sh "${mvnHome}/bin/mvn clean package"
    }
    
    stage('Test') {
        try {
            sh "${mvnHome}/bin/mvn test"
        } finally {
            junit '**/target/surefire-reports/*.xml'
        }
    }
    
    stage('Deploy') {
        if (env.BRANCH_NAME == 'main') {
            sh './deploy.sh production'
        } else {
            sh './deploy.sh staging'
        }
    }
}

Common Pipeline Steps

Source Control

// Git checkout
checkout scm

// Specific repository
git branch: 'main',
    url: 'https://github.com/user/repo.git',
    credentialsId: 'github-credentials'

// Checkout with options
checkout([
    $class: 'GitSCM',
    branches: [[name: '*/main']],
    extensions: [[$class: 'CloneOption', depth: 1]],
    userRemoteConfigs: [[url: 'https://github.com/user/repo.git']]
])

Credentials

// Username and password
withCredentials([usernamePassword(
    credentialsId: 'docker-hub',
    usernameVariable: 'DOCKER_USER',
    passwordVariable: 'DOCKER_PASS')]) {
    sh 'docker login -u $DOCKER_USER -p $DOCKER_PASS'
}

// SSH key
withCredentials([sshUserPrivateKey(
    credentialsId: 'deploy-key',
    keyFileVariable: 'SSH_KEY')]) {
    sh 'ssh -i $SSH_KEY user@server "deploy.sh"'
}

// Secret text
withCredentials([string(
    credentialsId: 'api-token',
    variable: 'API_TOKEN')]) {
    sh 'curl -H "Authorization: Bearer $API_TOKEN" api.example.com'
}

Docker Operations

// Build image
docker.build('my-image:${BUILD_NUMBER}')

// Build with Dockerfile path
docker.build('my-image', '-f docker/Dockerfile .')

// Push image
docker.withRegistry('https://registry.example.com', 'registry-credentials') {
    def image = docker.build('my-image:${BUILD_NUMBER}')
    image.push()
    image.push('latest')
}

// Run container
docker.image('node:16').inside {
    sh 'npm install'
    sh 'npm test'
}

Agent Configuration

Agent Types

// Any available agent
agent any

// Specific label
agent {
    label 'linux && docker'
}

// Docker agent
agent {
    docker {
        image 'maven:3.9-eclipse-temurin-17'
        args '-v $HOME/.m2:/root/.m2'
    }
}

// Dockerfile agent
agent {
    dockerfile {
        filename 'Dockerfile.build'
        dir 'docker'
        args '-v /tmp:/tmp'
    }
}

// Kubernetes agent
agent {
    kubernetes {
        yaml '''
apiVersion: v1
kind: Pod
spec:
  containers:
  - name: maven
    image: maven:3.9-eclipse-temurin-17
    command:
    - cat
    tty: true
  - name: docker
    image: docker:dind
    securityContext:
      privileged: true
'''
    }
}

Jenkins CLI

CLI Commands

# Download CLI
wget http://localhost:8080/jnlpJars/jenkins-cli.jar

# Get help
java -jar jenkins-cli.jar -s http://localhost:8080/ -auth user:token help

# List jobs
java -jar jenkins-cli.jar -s http://localhost:8080/ -auth user:token list-jobs

# Build job
java -jar jenkins-cli.jar -s http://localhost:8080/ -auth user:token build my-job

# Get job configuration
java -jar jenkins-cli.jar -s http://localhost:8080/ -auth user:token get-job my-job

# Install plugin
java -jar jenkins-cli.jar -s http://localhost:8080/ -auth user:token install-plugin git

# Restart Jenkins
java -jar jenkins-cli.jar -s http://localhost:8080/ -auth user:token safe-restart

Configuration as Code

JCasC Configuration

# jenkins.yaml
jenkins:
  systemMessage: "Jenkins configured automatically"
  securityRealm:
    local:
      allowsSignup: false
      users:
        - id: "admin"
          password: "${ADMIN_PASSWORD}"
  authorizationStrategy:
    globalMatrix:
      permissions:
        - "Overall/Administer:admin"
        - "Overall/Read:authenticated"
  
  nodes:
    - permanent:
        name: "build-agent-1"
        labelString: "linux docker"
        remoteFS: "/home/jenkins"
        launcher:
          ssh:
            host: "agent1.example.com"
            credentialsId: "agent-ssh-key"
            
credentials:
  system:
    domainCredentials:
      - credentials:
          - usernamePassword:
              id: "github-creds"
              username: "github-user"
              password: "${GITHUB_TOKEN}"
              
unclassified:
  slackNotifier:
    teamDomain: "myteam"
    tokenCredentialId: "slack-token"

Best Practices

Pipeline Best Practices

1. Use Declarative Pipeline when possible
2. Keep Jenkinsfile in source control
3. Use shared libraries for common code
4. Implement proper error handling
5. Use parallel stages for independent tasks
6. Clean workspace when needed
7. Set appropriate timeouts
8. Archive artifacts and test results
9. Use credentials binding for secrets
10. Implement proper notifications

Conclusion

Jenkins remains the most versatile and widely-adopted CI/CD platform, providing the flexibility to automate any software delivery workflow. Its extensive plugin ecosystem, Pipeline as Code capabilities, and distributed architecture make it suitable for projects of any size and complexity.

Whether implementing simple builds or complex multi-stage deployments, Jenkins provides the foundation for reliable, repeatable software delivery.

Developer: Jenkins Project

Download Options

Download Jenkins – Open Source Automation Server for CI/CD

Version 2.426

File Size: 100 MB

Download Now
Safe & Secure

Verified and scanned for viruses

Regular Updates

Always get the latest version

24/7 Support

Help available when you need it