01 / 14

What are Agents in jenkins?

Agents are lightweight Java processes that connect to the Jenkins controller to execute build tasks, enabling distributed builds across multiple machines with different operating systems and environments

Agents in Jenkins are the worker machines responsible for executing build jobs. They run as small Java client processes that establish a connection to the Jenkins controller, receive instructions, and perform tasks like compiling code, running tests, or creating artifacts. The agent architecture allows Jenkins to distribute workloads across multiple machines, each potentially with different operating systems, toolchains, or hardware configurations, all managed from a single central controller.

Jenkins uses a controller-agent (formerly master-slave) architecture where the controller manages the system state, schedules jobs, and serves the web UI, while agents execute the actual build tasks. The controller delegates work to agents, which run the builds and report results back. This separation ensures that heavy build workloads don't impact the responsiveness of the Jenkins web interface and allows builds to run on specialized hardware or operating systems.

Key Characteristics of Agents
  1. 1

    Lightweight: The agent client is small (around 170KB) and runs as a Java process, making it easy to deploy on any machine that supports Java.

  2. 2

    Connection-based: Agents connect to the controller and maintain a persistent connection, waiting for work assignments rather than requiring inbound connections from the controller.

  3. 3

    Self-registering: Once configured, agents announce their availability, capabilities, and labels to the controller, enabling dynamic task matching.

  4. 4

    Platform-independent: Agents can run on any operating system, enabling cross-platform builds where compilation might happen on Linux, testing on Windows, and packaging on macOS.

Agents can connect to the controller using several methods depending on network topology and security requirements. The most common is launching agents via SSH, where the controller initiates the connection. For environments where agents are behind firewalls, the JNLP (Java Web Start) or WebSocket methods allow agents to initiate outbound connections to the controller. In containerized environments, agents can run as Docker containers or Kubernetes pods that spin up only when needed and terminate after job completion.

Agents can be tagged with labels that describe their capabilities, such as 'linux', 'docker', 'high-memory', or 'arm64'. When defining a job, you specify label requirements, and Jenkins automatically assigns the job to an agent that matches all required labels. This abstraction decouples build logic from specific machine names, making pipelines more portable and infrastructure more flexible.

Jenkins includes a built-in node that runs within the controller process itself. While technically capable of running builds, this is strongly discouraged for security, performance, and scalability reasons. Best practice is to configure the built-in node with 0 executors and route all build work to dedicated agents. This separation ensures the controller remains responsive for scheduling and user interface tasks regardless of build load.

Agents operate with the permissions of the user account they run under. For security, production deployments should enable SSL/TLS for controller-agent communication, use SSH keys rather than passwords, and consider using ephemeral agents in containerized environments to ensure clean, isolated builds. The controller also needs to verify that connected agents are authorized to perform the tasks assigned to them.

Difficulty: 5/10
Topics: agent configuration, node provisioning, scaling

Scenario Questions

0-2 years experience
  1. 1

    How would you set up a new Jenkins agent on a Linux VM to run builds for a Java project?

  2. 2

    If a build that normally runs on a specific agent suddenly fails with “agent offline”, what steps would you take to investigate and fix it?

  3. 3

    What happens when you assign a label to a job but no agent currently has that label?

2-5 years experience
  1. 1

    We need to run builds on both Windows and Linux, but have limited hardware. How would you configure Jenkins agents to share resources while keeping environments isolated?

  2. 2

    During a pipeline run the agent disconnects after a few minutes. What could cause this, and how would you debug the issue?

  3. 3

    A recent change to the Docker image used for agents caused builds to hang. Walk me through how you’d identify the root cause and resolve it.

5-8 years experience
  1. 1

    Our CI system must handle 200 concurrent builds across multiple teams. Design a Jenkins agent strategy that balances load, minimizes queue time, and tolerates node failures.

  2. 2

    We’re considering moving from static agents to dynamic provisioning via Kubernetes. What trade‑offs would you evaluate, and how would you migrate existing pipelines?

  3. 3

    How would you implement security isolation between agents that run untrusted code while keeping performance overhead low?

8+ years experience
  1. 1

    Across the organization we have legacy on‑prem agents and new cloud‑based agents. How would you define a unified agent architecture that supports both, ensures consistent tooling, and simplifies maintenance?

  2. 2

    If we need to deprecate the current master‑agent model in favor of a distributed, event‑driven build execution platform, what are the key architectural considerations and migration steps?

  3. 3

    How would you establish governance policies for agent provisioning that balance cost, compliance, and developer autonomy across multiple product lines?

Follow-up Questions

  • What are the key steps you’d take to verify an agent’s health?
  • How would you decide between static and dynamic agents for a given workload?
  • Can you describe a time when an agent configuration caused a pipeline failure?