how jenkins works

🔹 How Jenkins Works for Pipelines

1️⃣ What is a Jenkins Pipeline?

A Jenkins Pipeline is a set of automated processes defining CI/CD workflows. It is written in Groovy-based DSL (Domain-Specific Language) and can be stored in Jenkinsfile in a Git repository.

2️⃣ Types of Pipelines in Jenkins

Pipeline Type
Description

Declarative Pipeline

Simplified, structured syntax for CI/CD

Scripted Pipeline

More flexible but complex, uses Groovy scripting

Multibranch Pipeline

Creates different pipelines for each Git branch

Shared Libraries

Reusable pipeline code for multiple projects


3️⃣ Jenkins Pipeline Workflow

1️⃣ Trigger → Jenkins is triggered via a Git push, webhook, or scheduled job 2️⃣ Checkout Code → Fetches latest code from GitHub/GitLab 3️⃣ Build Stage → Compiles the code (e.g., using Maven, Gradle, npm) 4️⃣ Test Stage → Runs Unit, Integration, or Security tests 5️⃣ Artifact Storage → Built files (e.g., JAR, WAR, Docker images) stored in Nexus, Artifactory, AWS S3 6️⃣ Deployment → Deploys to Docker, Kubernetes, AWS, or on-prem servers 7️⃣ Notification → Sends Slack, email, or webhook alerts


4️⃣ Example: Declarative Pipeline (Jenkinsfile)

pipeline {
    agent any  
    stages {
        stage('Checkout') {
            steps {
                git 'https://github.com/example/repo.git'
            }
        }
        stage('Build') {
            steps {
                sh 'mvn clean package'
            }
        }
        stage('Test') {
            steps {
                sh 'mvn test'
            }
        }
        stage('Deploy') {
            steps {
                sh 'kubectl apply -f deployment.yaml'
            }
        }
    }
}

5️⃣ Key Jenkins Pipeline Concepts

Component
Description

Agent

Defines where the pipeline runs (any, node, Docker, Kubernetes)

Stages

Major steps in a CI/CD pipeline (e.g., Build, Test, Deploy)

Steps

Individual tasks within a stage

Post

Defines actions like cleanup or notifications

Environment

Stores credentials, variables, and secrets securely


6️⃣ Jenkins Pipeline Integration

  • Git → Fetches source code

  • Docker → Builds & pushes container images

  • Kubernetes → Deploys applications

  • Terraform → Automates infrastructure provisioning

  • Prometheus/Grafana → Monitors builds and deployments


7️⃣ Jenkins Pipeline Execution Flow

1️⃣ Developer pushes code to GitHub 2️⃣ GitHub webhook triggers Jenkins pipeline 3️⃣ Jenkins checks out the code and runs the pipeline 4️⃣ Builds, tests, and deploys the application 5️⃣ Sends success or failure notification


🚀 Conclusion

Jenkins pipelines automate CI/CD, making deployments repeatable, scalable, and efficient across Docker, Kubernetes, AWS, and cloud environments.

Last updated