The Jenkins Master, often referred to as the Jenkins Server, is the core component in a Jenkins architecture. It orchestrates the entire Continuous Integration/Continuous Delivery (CI/CD) process and plays several key roles. Here's an overview:
Key Functions of Jenkins Master (Server):
- User Interface and Configuration Management: The Jenkins Master provides the web-based user interface (UI) through which users can configure jobs, view job statuses, manage plugins, and monitor build history. It allows users to define pipelines, schedule jobs, and manage credentials, among other configuration tasks.
- Job Scheduling and Distribution: The Jenkins Master is responsible for scheduling jobs to be executed based on triggers (e.g., code commits, time-based schedules). It can execute jobs directly on the master or distribute them to Jenkins agents (nodes) for execution. In larger setups, most jobs are executed on agents rather than the master itself.
- Build Orchestration: The Jenkins Master orchestrates the CI/CD pipeline by coordinating the various stages of a job, such as code checkout, build, test, and deploy. It manages the flow of information between different stages and keeps track of job progress and results.
- Plugin Management: The Jenkins Master manages and hosts the various plugins installed to extend Jenkins' functionality (e.g., Git, Docker, Kubernetes integrations). These plugins allow Jenkins to support a wide range of tools and platforms in the CI/CD ecosystem.
- Centralized Logging and Monitoring: The master collects and displays logs from all jobs and stages, providing a centralized view of the status and history of all builds and pipelines. It tracks build status, test results, and other metrics, helping users troubleshoot and optimize their CI/CD processes.
- Security and Access Control: The Jenkins Master handles user authentication, authorization, and other security configurations. It ensures that users have the appropriate access to pipelines, jobs, and credentials.
- Communication with Agents: The master communicates with Jenkins agents to delegate tasks. Agents can be configured on remote machines to distribute the load, and they perform the heavy lifting of executing jobs as instructed by the master.
Jenkins Agents
A Jenkins Agent (previously referred to as "Jenkins Slave") is a secondary machine that Jenkins Master delegates to execute tasks such as building, testing, or deploying projects. Agents offload the work from the Master, enabling the distributed execution of jobs across multiple environments.
Key Characteristics of Jenkins Agents:
- Job Execution: Agents handle the actual execution of jobs as directed by the Master, which includes compiling code, running tests, or deploying artifacts.
- Distributed Architecture: Agents allow Jenkins to scale horizontally by distributing workloads across multiple machines. This is beneficial when jobs need different environments (e.g., Linux, Windows, macOS) or when high workloads need to be balanced across multiple nodes.
- Communication with Master: Agents communicate with the Jenkins Master using various protocols (e.g., SSH, JNLP). The Master coordinates tasks, and agents run them.
- Environment Isolation: Each agent can be configured with different software environments, hardware resources, and system configurations, providing flexibility for executing diverse job requirements.
Agent Types:
- Static Agents: Permanently configured nodes that are always available to run jobs.
- Dynamic Agents: Created on-demand, often within cloud environments (e.g., Kubernetes, EC2 instances), and destroyed after the job finishes.
By utilizing agents, Jenkins optimizes resource usage, enabling parallel processing and reducing the load on the Master.
Jenkins Master vs. Jenkins Agent:
- Jenkins Master: Orchestrates the pipeline, schedules jobs, provides the UI, manages configurations, and can execute jobs if needed.
- Jenkins Agent: Executes the jobs (builds, tests, deployments) as per the instructions of the master. Agents are used to distribute the workload across multiple machines.
Typical Architecture:
In a distributed Jenkins setup:
- Master: Handles orchestration, scheduling, and provides the interface.
- Agents (Slaves): Are distributed across machines or environments to handle the actual execution of jobs (e.g., running tests or building software).
This architecture allows Jenkins to scale effectively and manage complex CI/CD pipelines across diverse environments.
Now Lets Create an agent by setting up a node on Jenkins
To create an agent (node) by setting up a new node on Jenkins, follow these steps:
Prerequisites:
- Jenkins master is already installed and running.
- The machine that you want to set up as an agent has network access to the Jenkins master.
Steps to Create and Configure a Jenkins Agent:
1. Login to Jenkins Master
- Open your Jenkins web interface (e.g., https://<your_jenkins_master_url>:8080).
- Log in with your Jenkins credentials.
2. Navigate to Manage Nodes
- From the Jenkins dashboard, go to Manage Jenkins.
- Click on Manage Nodes and Clouds under the "System Configuration" section.
3. Create a New Node
- Click on New Node in the left-hand sidebar.
- Enter a name for your new agent (e.g., linux-agent-1), select Permanent Agent, and click OK.
4. Configure Node Settings
In the configuration screen for the new node, set the following fields:
- Description: A brief description of the node (optional).
- # of executors: The number of jobs the agent can run in parallel (e.g., 2).
- Remote root directory: The directory on the agent machine where Jenkins will store files (e.g., /home/jenkins).
- Labels: Tags used to categorize the node (e.g., linux, docker, etc.). Labels are useful for assigning jobs to specific agents.
- Usage: Select how Jenkins will allocate jobs to this node:Use this node as much as possible: Jenkins will use this agent when available.Only build jobs with label expressions matching this node: The agent will only run jobs explicitly configured with its labels.
5. Launch Method
You will now configure how the Jenkins master connects to the agent. The most common methods are:
- Launch agent via SSH: The Jenkins master will connect to the agent via SSH.Enter the host of the agent machine.Provide the credentials (username and password or SSH key) for connecting to the agent. You can add credentials via Add button.
6. Save the Node Configuration
- After setting up the node's details and launch method, click Save to finalize the configuration.
7. Start the Agent
Depending on the launch method, start the agent:
- SSH Launch: Jenkins will automatically connect to the agent machine using SSH and start the agent process.
Jenkins will provide the exact command on the node's configuration page.
8. Verify the Agent Status
- Once the agent is started, go back to Manage Nodes.
- You should see the newly configured agent listed with a Connected status and a green checkmark.
- The node should now be available to run Jenkins jobs.
Conclusion:
After setting up the agent, Jenkins will be able to distribute jobs to this node according to the configurations and labels you have applied. This improves scalability and resource utilization in your CI/CD pipeline.