Mastering Jenkins Agents!

Mastering Jenkins Agents!

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):

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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.
  7. 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:

  1. Job Execution: Agents handle the actual execution of jobs as directed by the Master, which includes compiling code, running tests, or deploying artifacts.
  2. 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.
  3. Communication with Master: Agents communicate with the Jenkins Master using various protocols (e.g., SSH, JNLP). The Master coordinates tasks, and agents run them.
  4. 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.



要查看或添加评论,请登录

Riya Negi的更多文章

  • Kubernetes Overview

    Kubernetes Overview

    What is Kubernetes and Why Do We Call It K8s? Kubernetes (often abbreviated as K8s) is an open-source platform for…

    1 条评论
  • Jenkins Important Interview Questions

    Jenkins Important Interview Questions

    Important Interview Questions. Jenkins is a cornerstone of modern CI/CD pipelines, and mastering it can give you a…

  • Jenkins Declarative Pipeline with Docker

    Jenkins Declarative Pipeline with Docker

    Hello Connections, So we will start with Jenkin Declarative pipeline with Docker. Before that we should know why to…

    2 条评论
  • Jenkins Declarative Pipeline

    Jenkins Declarative Pipeline

    So, Lets go deep into Jenkins and learn to start Pipeline in Jenkins. First let basics of Pipeline and all stuffs.

  • Complete Jenkins CI/CD Project

    Complete Jenkins CI/CD Project

    Let Set Up the Jenkins CI/CD Project For this follow these step carefully and here we begins Step 1: Fork the…

  • Jenkins Freestyle Project for DevOps Engineers.

    Jenkins Freestyle Project for DevOps Engineers.

    What is CI/CD? CI/CD stands for Continuous Integration (CI) and Continuous Deployment (CD) (or Continuous Delivery). It…

  • Getting Started with Jenkins

    Getting Started with Jenkins

    What is Jenkins? Jenkins is an open-source continuous integration (CI) and continuous delivery/deployment (CD)…

  • Docker Important interview Questions.

    Docker Important interview Questions.

    1. What is the difference between an Image, Container, and Engine? Image: An image is a lightweight, stand-alone…

  • Docker Cheat Sheet

    Docker Cheat Sheet

    Docker is a powerful tool for containerization that enables developers to package applications along with their…

  • Docker Project for DevOps Engineers

    Docker Project for DevOps Engineers

    Lets build the first ngnix container and see it is working or not? So we will give command as -docker run -d -p 80:80…