Jenkins +
Jenkins is one of the most widely adopted open-source platforms for continuous integration and continuous delivery. Built on Java, it automates the software lifecycle from code checkout and compilation to testing and deployment. Using Jenkins effectively requires a clear mental model of its architecture: the components that constitute the system, and the concepts that define how delivery workflows are expressed. This guide examines both layers and concludes with a complete, working example.
Jenkins Master
The Master serves as the control center of a Jenkins installation. Its primary responsibilities include:
- Providing the web-based management interface for configuration and operation
- Scheduling build jobs and dispatching them to suitable nodes
- Monitoring agent availability and load
- Storing global configuration, installed plugins, and build history
In production environments, the Master typically does not execute builds itself. It focuses on orchestration and administration, leaving the actual work to connected agents.
Jenkins Agent
An Agent is a machine that carries out build tasks on behalf of the Master. Agents connect to the Master to receive instructions and report results. Distributing work across agents offers several advantages:
- Resource isolation: Builds run on separate machines, reducing interference between jobs
- Environment targeting: You can provision Windows agents for desktop application compilation and Linux agents for Docker image builds
- Horizontal scalability: Adding agents increases concurrent execution capacity and overall throughput
Executor
An Executor is essentially a worker thread on a node. Each Executor can run only one build at a time. A node may be configured with multiple Executors to process jobs in parallel; the default is one. If a job occupies an Executor, additional queued jobs wait until capacity becomes available.
Plugin System
Plugins form the heart of the Jenkins ecosystem. Nearly every capability beyond the core runtime is delivered through a plugin. Common examples include:
- Git and Subversion for source control
- Maven and Gradle for project builds
- Pipeline for workflow definition
- Blue Ocean for a modern visual interface
- Docker and Kubernetes for container and cluster integration
The extensible plugin architecture allows teams to adapt Jenkins to virtually any technology stack or delivery process.
Job and Workspace
A Job is the fundamental unit of execution in Jenkins. Common job types include freestyle projects, Pipeline projects, and Multibranch Pipelines. Each job runs within a Workspace, a dedicated directory on the agent where source code is checked out, compiled, and where build outputs are temporarily stored.
Credentials
Jenkins provides a centralized credential store for sensitive information such as Git usernames and passwords, SSH private keys, and API tokens. Storing secrets here prevents them from being exposed in plain text inside build scripts or job configurations.
Core Concepts
Pipeline
A Pipeline expresses the delivery process as code, connecting stages such as source checkout, compilation, testing, and deployment into a single automated flow. Pipelines are versionable, reviewable, and reusable. Jenkins supports two syntax styles:
- Declarative Pipeline: Offers a fixed, structured syntax that is easier to read and maintain. This is the recommended approach for most teams.
- Scripted Pipeline: Written in Groovy, it provides greater flexibility but comes with higher complexity and a steeper learning curve.
Jenkinsfile
The Jenkinsfile is a text file that contains the Pipeline definition. It is typically stored in the root directory of the source repository and versioned alongside application code. This practice—often summarized as "Pipeline as Code"—ensures that delivery logic evolves together with the software it delivers.
Stage and Step
A Pipeline is composed of Stages and Steps:
- A Stage represents a logical phase of the delivery process, such as Build, Test, or Deploy. Stages help visualize progress in the Jenkins UI and organize the workflow into meaningful blocks.
- A Step is the smallest unit of execution within a stage. Examples include running a shell command with
sh, checking out source code withgit, or archiving files.
Node and Agent
Within a Pipeline, the agent directive determines where the work executes. agent any allows the Pipeline to run on any available node, while agent { label 'linux' } restricts execution to nodes carrying the specified label. This mechanism binds the abstract Pipeline definition to concrete infrastructure.
Trigger
Triggers control when a build starts automatically. Common triggering strategies include:
- Starting a build after a code commit
- Running on a fixed schedule using cron-like syntax
- Launching after an upstream job completes
- Receiving a remote webhook from a source control platform or external system
Build and Artifact
Every execution of a job produces a Build, identified by an incrementing build number. Files generated during the build—such as JAR packages, WAR files, or Docker images—are known as Artifacts. Jenkins can archive these artifacts so they remain available for later deployment or downstream consumption.
Complete Example: Declarative Pipeline
The following Jenkinsfile demonstrates how these components and concepts work together. It defines a four-stage delivery flow and archives the compiled output when the run finishes.
pipeline {
agent any
stages {
stage('Checkout') {
steps {
git branch: 'main', url: 'https://github.com/example/app.git'
}
}
stage('Build') {
steps {
sh 'mvn clean package -DskipTests'
}
}
stage('Test') {
steps {
sh 'mvn test'
}
}
stage('Deploy') {
steps {
sh './deploy.sh'
}
}
}
post {
always {
archiveArtifacts artifacts: 'target/*.jar', fingerprint: true
}
}
}
The Pipeline checks out source code from Git, compiles the project with Maven, runs the test suite, and executes a deployment script. Regardless of whether the build succeeds or fails, the post block archives the resulting JAR files and records fingerprints for traceability.
Summary
Understanding Jenkins means distinguishing between two layers. Components answer the question of what the system is made of: the Master, Agents, Executors, plugins, Jobs, Workspaces, and Credentials. Concepts answer how the delivery process is expressed: Pipelines, Jenkinsfiles, Stages, Steps, Triggers, Builds, and Artifacts. Once these fundamentals are clear, you can write practical Pipelines tailored to real projects and assemble a maintainable, efficient CI/CD system.