DEV Community

Cover image for Jenkins Architecture and Working Pattern with an Example.
Giri Dharan
Giri Dharan

Posted on

Jenkins Architecture and Working Pattern with an Example.

Jenkins is an open-source automation server that's a powerhouse for Continuous Integration (CI) and Continuous Delivery (CD). Think of it as the conductor of an orchestra, making sure all the different instruments (your development tasks) play together in harmony to deliver a symphony (your software)!

At its core, Jenkins uses a controller-agent architecture.

Here's how it generally works:

Jenkins Controller (formerly Master): This is the brain of the operation.
It manages everything: scheduling build jobs, assigning tasks to agents, and keeping track of plugins and settings.
It hosts the web interface where you configure jobs and monitor progress.
It stores job configurations and build history.
Jenkins Agent (formerly Slave): These are the workhorses.
Agents are separate machines (physical, virtual, or even containers) that execute the tasks the controller assigns to them.
They can run on different operating systems (Windows, Linux, macOS) to support cross-platform testing.
Using multiple agents allows Jenkins to distribute the workload and run many tasks in parallel, preventing the controller from getting overloaded.

How it works with a real-time example (using Jenkins Pipeline):

The modern way to use Jenkins is with Jenkins Pipelines, which define your entire delivery process as code in a Jenkinsfile. This file lives alongside your application's code in a source control repository (like Git), meaning your automation workflow is versioned and reviewable just like any other code.

Let's imagine a team developing a web application:

Code Commit & Trigger: A developer pushes new code changes to a Git repository.
Real-time example: git push origin feature/new-login-page
A webhook or polling mechanism in Jenkins detects this change.
Pipeline Execution: Jenkins reads the Jenkinsfile from the repository. This file defines a series of stages, like "Build," "Test," and "Deploy".
Real-time example Jenkinsfile snippet (Declarative Pipeline) :
null
Task Delegation: The Jenkins Controller schedules these stages and delegates the actual execution steps to available agents.
An agent checks out the code, runs the mvn clean install command to build the application, then mvn test for unit tests.
Reporting and Artifacts: The agent sends the results (success/failure, test reports) back to the controller.
If the build is successful, the agent might publish the build artifact (e.g., a .jar or Docker image) to an artifact registry.
Further Actions: The controller updates the build status in the Jenkins UI and can trigger downstream jobs or send notifications (e.g., to Slack or email).
If all tests pass, the "Deploy to Staging" stage runs, and then, if configured, the "Deploy to Production" stage for the main branch.

This entire process ensures that every code change is automatically built, tested, and potentially deployed, catching issues early and accelerating the software delivery process.

Top comments (0)