Jenkins Fundamentals

Learn Jenkins fundamentals from scratch, including architecture, installation, pipelines, jobs, agents, plugins, CI/CD workflow, and production best practices with real-world examples.

Jenkins Fundamentals

Introduction

Jenkins is one of the world's most popular Continuous Integration (CI) and Continuous Delivery (CD) automation servers. It helps development teams automate software building, testing, packaging, and deployment, reducing manual effort and increasing delivery speed.

In modern software development, developers commit code multiple times a day. Jenkins automatically detects these changes, builds the application, runs tests, creates deployment artifacts, and can even deploy applications to different environments.

Whether you're a Java developer, DevOps engineer, Cloud engineer, or Solution Architect, Jenkins is a fundamental skill for building enterprise CI/CD pipelines.


Learning Objectives

After completing this guide, you will understand:

  • What Jenkins is
  • Why Jenkins is used
  • CI/CD concepts
  • Jenkins Architecture
  • Master-Agent Architecture
  • Jenkins Jobs
  • Jenkins Pipeline
  • Jenkinsfile
  • Plugins
  • Build Triggers
  • Workspaces
  • Build Artifacts
  • Production Workflow
  • Best Practices

What is Jenkins?

Jenkins is an open-source automation server that automates software development tasks such as:

  • Source Code Checkout
  • Compilation
  • Unit Testing
  • Static Code Analysis
  • Packaging
  • Docker Image Creation
  • Deployment
  • Notifications

Instead of manually executing these steps, Jenkins performs them automatically whenever code changes occur.


Why Do We Need Jenkins?

Without Jenkins:

Developer

Write Code

Commit Code

Manual Build

Manual Testing

Manual Deployment

Production

Problems

  • Human Errors
  • Slow Releases
  • Manual Testing
  • Inconsistent Deployments
  • Late Bug Detection

With Jenkins:

Developer

Git Push

Webhook

Jenkins

Build

Test

Package

Deploy

Notify Team

Benefits

  • Automation
  • Faster Releases
  • Better Code Quality
  • Reliable Deployments
  • Continuous Feedback

What is CI/CD?

Continuous Integration (CI)

Continuous Integration means developers frequently merge code into a shared repository.

Each commit automatically triggers:

  • Build
  • Unit Tests
  • Code Analysis
  • Packaging

Goal:

Detect issues early.


Continuous Delivery (CD)

Continuous Delivery automatically prepares software for deployment.

Pipeline:

Build

Test

Package

Deploy to QA

Ready for Production

Production deployment requires approval.


Continuous Deployment

Everything is automated.

Developer

Commit

Build

Test

Deploy Production

Live

No manual approval required.


Jenkins Architecture

                Developer
                     │
                     ▼
              Git Repository
                     │
             Git Webhook/Event
                     │
                     ▼
              Jenkins Controller
                     │
      ┌──────────────┴──────────────┐
      ▼                             ▼
 Build Agent 1                Build Agent 2
      │                             │
      ▼                             ▼
 Build/Test                  Docker Build
      │                             │
      └──────────────┬──────────────┘
                     ▼
                Artifact Repository
                     │
                     ▼
              Deploy to Servers

Jenkins Components

Jenkins Controller

Responsible for:

  • Managing pipelines
  • Scheduling builds
  • Managing agents
  • Installing plugins
  • Managing credentials
  • Monitoring jobs

Jenkins Agent

Agents perform actual work.

Examples:

  • Build Java application
  • Run Maven
  • Execute Tests
  • Build Docker Image
  • Deploy Application

Large organizations use dozens or hundreds of agents.


Jenkins Jobs

A Job is a task Jenkins executes.

Examples

  • Build Job
  • Test Job
  • Deploy Job
  • Backup Job
  • Cleanup Job

Types of Jenkins Jobs

Freestyle Project

Classic UI-based job.

Suitable for:

  • Beginners
  • Simple automation

Pipeline Job

Pipeline defined as code.

Uses:

Jenkinsfile

Recommended for production.


Multibranch Pipeline

Automatically builds every Git branch.

Example

main

develop

feature/login

feature/payment

Each branch has its own pipeline.


Folder

Organizes jobs.

Example

Backend

Frontend

DevOps

Mobile


What is a Jenkins Pipeline?

Pipeline is a series of automated stages.

Example

Checkout Code

↓

Compile

↓

Unit Test

↓

Package

↓

Docker Build

↓

Push Image

↓

Deploy

↓

Integration Test

↓

Production

Pipeline Stages

Typical stages

  • Checkout
  • Build
  • Test
  • Sonar Analysis
  • Package
  • Docker Build
  • Push Registry
  • Deploy
  • Smoke Test
  • Notify

Jenkinsfile

Jenkinsfile stores pipeline configuration in Git.

Example

pipeline {

    agent any

    stages {

        stage('Build') {
            steps {
                sh 'mvn clean package'
            }
        }

        stage('Test') {
            steps {
                sh 'mvn test'
            }
        }
    }
}

Benefits

  • Version Controlled
  • Reusable
  • Reviewable
  • Easy Maintenance

Jenkins Plugins

Plugins extend Jenkins functionality.

Popular Plugins

  • Git Plugin
  • Pipeline Plugin
  • Docker Plugin
  • Kubernetes Plugin
  • Maven Plugin
  • Gradle Plugin
  • SonarQube Plugin
  • Slack Plugin
  • Email Extension
  • Blue Ocean

Build Triggers

Jenkins can automatically start builds using:

  • Git Webhook
  • Scheduled Cron
  • Poll SCM
  • Manual Build
  • Upstream Job
  • API Trigger

Build Workspace

Workspace is the directory where Jenkins performs builds.

Example

workspace/

src/

pom.xml

target/

logs/

reports/

Workspace is cleaned after builds depending on configuration.


Build Artifacts

Artifacts are files generated during the build.

Examples

  • JAR
  • WAR
  • Docker Image
  • ZIP
  • Reports
  • Logs

Artifacts are stored in:

  • Nexus
  • Artifactory
  • AWS S3
  • Jenkins Archive

Build Status

Common build results

Status Meaning
Success Build Passed
Failed Build Failed
Unstable Tests Failed
Aborted Build Cancelled
Running Build In Progress

Typical Enterprise CI/CD Flow

Developer

    │

Git Push

    │

GitHub/GitLab

    │

Webhook

    │

Jenkins

    │

Checkout

    │

Build

    │

Unit Tests

    │

SonarQube

    │

Package

    │

Docker Build

    │

Push Registry

    │

Deploy Dev

    │

Integration Tests

    │

Deploy QA

    │

Approval

    │

Deploy Production

    │

Monitoring

Advantages of Jenkins

  • Open Source
  • Large Plugin Ecosystem
  • Easy Integration
  • Pipeline as Code
  • Distributed Builds
  • Docker Support
  • Kubernetes Support
  • Cloud Ready
  • Easy Automation
  • Large Community

Limitations

  • Plugin Compatibility Issues
  • Initial Configuration Complexity
  • UI Can Be Complex
  • Single Controller Bottleneck
  • Requires Maintenance
  • Security Requires Proper Configuration

Production Best Practices

  • Store pipelines in Git
  • Use Jenkinsfile
  • Use Shared Libraries
  • Keep plugins updated
  • Secure credentials
  • Enable backups
  • Use dedicated build agents
  • Monitor build health
  • Archive artifacts
  • Use role-based access control

Real-World Example

A Spring Boot developer pushes code to GitHub.

  1. Developer commits code.
  2. GitHub webhook triggers Jenkins.
  3. Jenkins checks out the source code.
  4. Maven compiles the project.
  5. Unit tests are executed.
  6. SonarQube performs static code analysis.
  7. A JAR file is generated.
  8. Docker image is created.
  9. Docker image is pushed to the container registry.
  10. Kubernetes deploys the new application.
  11. Slack notification is sent to the team.

This entire process typically completes in just a few minutes without manual intervention.


Interview Tips

Remember these key points:

  • Jenkins is an automation server.
  • CI integrates code continuously.
  • CD automates software delivery.
  • Jenkins Controller manages jobs and agents.
  • Agents execute builds.
  • Jenkinsfile enables Pipeline as Code.
  • Plugins extend Jenkins functionality.
  • Artifacts are outputs generated during builds.
  • Webhooks automatically trigger pipelines.
  • Modern enterprises prefer Pipeline Jobs over Freestyle Jobs.

Summary

Jenkins is the backbone of modern CI/CD automation. It helps teams build, test, package, and deploy applications consistently and efficiently. Understanding Jenkins architecture, jobs, pipelines, plugins, and automation workflows provides a strong foundation for DevOps, Cloud, and Software Engineering roles.

In the next chapter, you'll explore Jenkins Advanced Concepts, including Pipeline as Code, Shared Libraries, Distributed Builds, Docker and Kubernetes integration, security, scalability, and production-grade CI/CD architectures.