Ephemeral vs. Persistent Agents: Two Philosophies for Running Jenkins Builds

Ephemeral vs. Persistent Agents: Two Philosophies for Running Jenkins Builds

A complete, beginner-to-advanced walkthrough of the two fundamental ways Jenkins agents can exist — always-on and reused, or disposable and freshly created — and how to choose between them.

Imagine two very different ways of hosting a dinner party every single week. One host owns a permanent dining set — the same table, chairs, and dishes, washed and reused every time, always ready but slowly accumulating wear, the occasional chip, and last week’s leftover crumbs if nobody cleans thoroughly. Another host rents a completely fresh set of furniture and dishware for every single party, returning everything afterward — guaranteed spotless every time, but with a setup delay before each event and a rental cost attached to every single gathering. Neither approach is universally “correct” — it depends on how often parties happen, how much consistency matters, and what budget exists. Jenkins agents face this exact same fundamental choice, known as ephemeral versus persistent agents.

1What Are Ephemeral and Persistent Agents?

Let’s establish a precise, shared vocabulary before comparing the two approaches in depth.

A persistent agent is a long-lived machine — physical, virtual, or otherwise — that stays registered with the Jenkins controller continuously, ready to accept new builds at any time, and reused across many builds over its lifetime, often for weeks, months, or years without ever being torn down.

An ephemeral agent, by contrast, is created fresh specifically to run one build (or a small handful of builds), and is destroyed immediately afterward. It typically exists as a container or a cloud-provisioned virtual machine, spun up on demand by a cloud plugin, used briefly, and then discarded entirely — leaving nothing behind for the next build to accidentally inherit.

Simple Analogy

A persistent agent is like a shared office desk that different employees use throughout the week — efficient and always available, but gradually accumulating someone else’s sticky notes, coffee rings, and misplaced staplers. An ephemeral agent is like a hotel room, freshly cleaned and reset before every single guest, guaranteeing the same pristine experience every time, at the cost of the housekeeping effort required to reset it.

i
Neither Is “The Right Answer”

Both models are widely used in production Jenkins installations today, often within the very same organization — the right choice depends heavily on workload characteristics, infrastructure maturity, and how much environmental consistency actually matters for a given kind of build.

2Why Both Models Exist

Understanding the historical and practical pressures behind each model clarifies why this is a genuine trade-off, not a solved problem.

Persistent agents were Jenkins’ original, default model — in the early days of continuous integration, provisioning a fresh machine for every single build simply wasn’t practical or fast enough. Teams registered a fixed pool of build machines once, and those machines quietly ran build after build for as long as they remained useful. This model is simple to reason about and avoids any per-build provisioning delay.

As containerization and cloud infrastructure matured, a new pressure emerged: growing awareness that long-lived machines slowly accumulate “environment drift” — leftover files, subtly different installed tool versions, cached state — that can cause a build to behave inconsistently depending purely on which specific agent happened to run it. Ephemeral agents emerged directly as a response to this problem, using the same disposability that made containers popular elsewhere in software infrastructure to guarantee a clean, identical starting environment on every single build.

Origin

Persistent: Born From Necessity

Long-lived agents were the practical default before fast, reliable dynamic provisioning technology existed.

Origin

Ephemeral: Born From Drift

Disposable agents emerged specifically to eliminate the “works on this agent, not that one” inconsistency long-lived machines can accumulate.

“Persistent agents optimize for speed and simplicity today; ephemeral agents optimize for consistency and cleanliness across every tomorrow.”

3Architecture & Core Components of Each Model

Both models share the same underlying controller-agent communication mechanism, but differ sharply in how the agent itself comes to exist.

Persistent

Static Agent Registration

An administrator manually configures the agent’s connection details once, and it remains a known, named entry in Jenkins’ agent list indefinitely.

Persistent

Long-Lived Workspace

The agent’s local working directory persists between builds, potentially retaining cached dependencies or build artifacts from prior runs.

Ephemeral

Cloud Plugin & Template

A cloud plugin (Kubernetes, Docker, or a public cloud provider) provisions a brand-new agent on demand, based on a predefined template.

Ephemeral

Fresh Workspace, Every Time

Because the underlying container or virtual machine is newly created, its workspace starts completely empty on every single build, with nothing carried over from any previous run.

Underneath both models, the same remoting communication channel connects the agent to the controller once it’s up and running — the architectural difference lies entirely in how and when that agent comes into existence and how long it’s expected to stick around afterward.

The Executor Concept Applies to Both

Whether persistent or ephemeral, an agent still exposes one or more “executors” — available work slots the controller can assign builds to — the scheduling logic itself doesn’t fundamentally care which model an available executor belongs to.

4How Each Model Actually Comes to Life Internally

The internal mechanics reveal exactly where the “speed vs. cleanliness” trade-off actually comes from.

For a persistent agent, once initially registered, Jenkins simply waits for that specific, known machine to have a free executor. When a matching build needs to run, it’s dispatched immediately — there’s no provisioning step at all, since the machine has been sitting ready the entire time.

For an ephemeral agent, the moment a build needs an agent that no existing idle machine can satisfy, the controller’s cloud plugin sends a provisioning request to the underlying provider, which creates a brand-new container or virtual machine from a template. Only once that new resource finishes starting and connects back to the controller can the waiting build actually begin.

flowchart TD
    A[Build needs an agent] --> B{Persistent agent free & matching?}
    B -- Yes --> C[Build starts immediately, no provisioning]
    B -- No --> D{Ephemeral cloud configured for this label?}
    D -- Yes --> E[New container/VM provisioned from template]
    E --> F[Agent connects back to controller]
    F --> G[Build starts on freshly created agent]
    D -- No --> H[Build waits in queue]
        
FIG 1 — Where the persistent-vs-ephemeral trade-off actually happens: the provisioning step

This single difference — whether a provisioning step exists at all — is the root cause of nearly every practical distinction between the two models. Persistent agents trade the guarantee of a clean environment for the guarantee of no per-build startup delay; ephemeral agents make the opposite trade.

Simple Analogy

It’s the difference between a taxi that’s already idling at the curb versus calling a rideshare that needs a few minutes to arrive — one is instantly available because it was already there waiting; the other guarantees a car that hasn’t been driven by anyone else today, at the cost of a short wait.

5Data Flow & Lifecycle, Side-by-Side

Looking at the two life cycles next to each other makes the differences concrete.

1

Persistent: Registered Once

An administrator configures the machine’s connection details a single time, and it remains part of the agent pool from that point forward.

2

Persistent: Reused Indefinitely

The same machine runs build after build, potentially for months or years, only occasionally taken offline for maintenance or eventual decommissioning.

3

Ephemeral: Created Per Build

A fresh container or virtual machine is provisioned the moment a matching build needs one, using a predefined, version-controlled template.

4

Ephemeral: Used Exactly Once

The newly created agent typically runs a single build, and rarely more than a handful, before it’s considered to have served its purpose.

5

Ephemeral: Torn Down Immediately

Once idle for longer than a configured timeout, the underlying resource is automatically deleted by the cloud provider, leaving no trace behind.

The key structural difference in this lifecycle comparison is where the “reset” happens. A persistent agent is reset — if at all — only through deliberate maintenance actions performed by a human or a scheduled job. An ephemeral agent is reset automatically and completely, simply by virtue of being destroyed and recreated from scratch for the next build.

6Advantages, Disadvantages & Trade-offs

Each model shines in different circumstances, and understanding both sides clearly is essential for making a good choice.

Persistent Agent Advantages

  • Zero per-build provisioning delay — the machine is always ready.
  • Can maintain useful local caches (dependencies, compiled artifacts) across builds, speeding up repeated work.
  • Simpler to reason about for small teams without mature cloud infrastructure.
  • Well-suited to specialized, hard-to-provision hardware (GPUs, unusual peripherals).

Persistent Agent Disadvantages

  • Accumulates environment drift over time without disciplined maintenance.
  • Pays for idle capacity around the clock, even outside peak build hours.
  • A misconfiguration or corruption on the machine silently affects every future build until noticed.
  • Scaling capacity requires manually provisioning and registering new machines.

Ephemeral Agent Advantages

  • Guarantees a clean, drift-free environment on every single build.
  • Scales elastically with actual demand, avoiding idle-capacity cost.
  • Naturally isolates untrusted or risky builds, since nothing persists afterward.
  • New agent types can be added by simply defining a new template, no physical provisioning required.

Ephemeral Agent Disadvantages

  • Introduces cold-start provisioning delay on every build that needs a new agent.
  • Can’t easily benefit from warm, pre-populated dependency caches without extra caching infrastructure.
  • Depends entirely on the health and responsiveness of the underlying cloud/cluster provider.
  • Requires genuine operational investment in templates, quotas, and provisioning infrastructure.

7Security Considerations

The two models carry meaningfully different security profiles, worth weighing explicitly.

A persistent agent, reused across many different builds over a long period, accumulates a kind of shared trust surface: any credentials, cached files, or leftover processes from one build could, in principle, be visible to a later, unrelated build running on that same machine. An ephemeral agent largely eliminates this specific risk, since nothing survives from one build to the next.

!
Persistent Agents and Untrusted Code

Running untrusted pull-request builds on the same long-lived persistent agent pool used for trusted, credentialed production pipelines is a meaningfully higher risk than doing so on freshly-provisioned, disposable ephemeral agents.

ANTI-PATTERN-01 Avoid
Problem

Assuming ephemeral agents are automatically secure simply because they’re disposable, while neglecting the security of the templates and images they’re built from.

Why It’s Harmful

A template built from an outdated or vulnerable base image recreates that exact same vulnerability on every single build, disposability notwithstanding.

Correct Approach

Treat ephemeral agent templates as production infrastructure code requiring the same patching discipline and review as any long-lived system.

Whichever model is chosen, credential handling deserves equal care — persistent agents need periodic credential rotation and access review, while ephemeral agent templates need careful control over exactly which credentials get injected into every freshly-provisioned instance.

8Monitoring, Logging & Metrics

Each model benefits from a distinct monitoring emphasis, reflecting where its particular risks tend to appear.

Persistent: Drift and Health Auditing

Periodically auditing installed tool versions, disk usage, and leftover files on long-lived agents helps catch environment drift before it silently causes a confusing, hard-to-reproduce build failure.

Ephemeral: Provisioning Latency and Failure Tracking

Because ephemeral agents introduce a provisioning step on every build, tracking how long that step takes — and how often it fails — is the single most valuable metric for this model specifically.

Both: Executor Utilization

Regardless of model, tracking how much available executor capacity sits idle versus busy remains a universally useful signal for right-sizing the overall fleet.

Always-On
Persistent Agent Availability
On-Demand
Ephemeral Agent Availability
Hybrid
Common Real-World Mix

9Design Patterns & Anti-Patterns

Mature Jenkins operators tend to converge on a shared set of strategies for getting the best of both models.

Pattern

Persistent for Specialized Hardware

Keeping a small, carefully-maintained pool of persistent agents specifically for workloads needing GPUs or other hardware that’s impractical to provision dynamically for every build.

Pattern

Ephemeral as the Elastic Default

Routing the bulk of ordinary build traffic to ephemeral agents, letting capacity scale automatically with demand rather than being capped by a fixed pool size.

Pattern

External Caching Layer for Ephemeral Agents

Using a shared, external dependency cache (rather than relying on local disk persistence) to give ephemeral agents much of the speed benefit persistent agents get from local caching, without sacrificing their disposability.

ANTI-PATTERN-02 Avoid
Problem

Letting a persistent agent fleet grow “organically” over years, with manually-installed tools and undocumented configuration nobody can confidently reproduce from scratch.

Why It’s Harmful

The fleet becomes an irreplaceable, fragile snowflake — a single hardware failure or accidental corruption can become a genuine crisis with no clean way to recover.

Correct Approach

Manage persistent agent configuration through infrastructure-as-code and automated provisioning scripts, treating even long-lived machines as reproducible rather than hand-crafted and irreplaceable.

10Best Practices & Common Mistakes

A handful of consistent habits keep either model — or a mix of both — running smoothly.

i
Best Practice

Default to ephemeral agents for anything where environmental consistency matters most, and reserve persistent agents deliberately for workloads with a clear, specific reason to need them.

i
Best Practice

Schedule regular maintenance windows for any persistent agents that do exist, treating periodic cleanup and patching as a non-optional recurring task rather than a reactive fix.

!
Common Mistake

Choosing persistent agents purely out of habit or familiarity, without seriously evaluating whether the resulting environment drift is quietly causing intermittent build failures.

!
Common Mistake

Adopting ephemeral agents without first solving dependency caching, resulting in every single build paying a full, uncached dependency-download penalty on top of the provisioning delay.

A direct, side-by-side comparison makes the decision easier to reason about for a specific workload.

FactorPersistent AgentEphemeral Agent
Startup delay per buildNoneProvisioning (“cold start”) delay
Environment consistencyCan drift over timeGuaranteed clean every time
Cost modelPays for idle timePays only for actual usage
Local cachingNatural and freeRequires external caching infrastructure
Best suited forSpecialized hardware, low build volumeElastic, high-volume, consistency-sensitive workloads

A Simple Starting Heuristic

If a workload’s build volume is highly variable, or environmental consistency has caused real problems in the past, lean ephemeral. If a workload needs specialized, hard-to-provision hardware, or build volume is small and steady, a persistent agent may still be the pragmatic choice.

12Hybrid Fleets: Using Both Together

In practice, most mature Jenkins installations don’t pick one model exclusively — they blend both deliberately.

A common, well-tested pattern is running a small, carefully maintained pool of persistent agents for specific, well-understood needs — a handful of machines with specialized hardware, or agents dedicated to unusually long-running jobs where a cold start would be wasteful — while routing the overwhelming majority of ordinary build traffic to an elastic pool of ephemeral agents.

flowchart LR
    A[Incoming builds] --> B{Needs specialized hardware or is latency-critical?}
    B -- Yes --> C[Persistent agent pool]
    B -- No --> D[Ephemeral cloud-provisioned pool]
        
FIG 2 — A common hybrid routing strategy combining both models

This hybrid approach captures much of the best of both worlds: the reliability and low-latency of persistent agents where it genuinely matters, and the elastic scalability and guaranteed cleanliness of ephemeral agents everywhere else. It does, however, require maintaining two distinct sets of operational practices simultaneously, which is itself a real cost worth acknowledging rather than ignoring.

13Real-World & Industry Examples

Both models — and their combination — show up constantly across real production Jenkins environments.

Legacy Hardware-in-the-Loop Testing

Companies testing embedded software against physical hardware devices often have no choice but to run persistent agents physically wired to that hardware, since an ephemeral, cloud-provisioned agent has no way to connect to a specific physical test rig.

Elastic Kubernetes-Based Microservice CI

Fast-growing organizations building dozens of independent microservices commonly run their entire ordinary build fleet as ephemeral Kubernetes pods, scaling smoothly with commit volume without maintaining any fixed-size static pool at all.

Financial Services Hybrid Fleets

Regulated financial organizations often maintain a small, tightly-controlled persistent agent pool for compliance-sensitive release pipelines, while routing everyday development and testing builds to a much larger ephemeral pool for cost efficiency.

14Frequently Asked Questions

Q1Can a single Jenkins controller manage both persistent and ephemeral agents simultaneously?

Yes — this is extremely common and is exactly what a hybrid fleet setup looks like, with different labels routing different kinds of builds to whichever agent type fits best.

Q2Is it possible to make an ephemeral agent behave more like a persistent one?

To some extent — techniques like external dependency caching can recover much of the speed benefit persistent agents get from local caching, though the fundamental per-build provisioning delay generally remains.

Q3Do ephemeral agents completely eliminate environment drift?

They eliminate drift between builds, but the underlying template or base image itself can still become outdated over time, so it still needs regular maintenance — just at the template level rather than on individual machines.

Q4Which model is generally recommended for a team just starting out?

Many teams starting with modest build volume and simple infrastructure find persistent agents easier to set up initially, then migrate toward ephemeral agents as build volume, team size, or consistency requirements grow.

Q5Does choosing ephemeral agents mean giving up on fast, cached builds entirely?

No — many organizations successfully pair ephemeral agents with a shared, external caching layer, getting most of the speed advantage of local caching without sacrificing the guarantee of a clean environment.

15Summary and Key Takeaways

Ephemeral and persistent agents represent two genuinely different philosophies for solving the same underlying problem: giving Jenkins somewhere to actually run its builds. Persistent agents offer speed and simplicity by staying always-on and reused, at the cost of gradually accumulating drift and paying for idle capacity. Ephemeral agents offer guaranteed cleanliness and elastic scaling by being created fresh and destroyed after use, at the cost of per-build provisioning delay and the need for more sophisticated supporting infrastructure. Neither model is universally superior — the right answer depends on workload characteristics, and most mature organizations end up deliberately blending both, using each where its particular strengths matter most.

Key Takeaways

  • The core trade-off is speed versus cleanliness — persistent agents are instantly ready; ephemeral agents guarantee a fresh environment.
  • Provisioning delay is the defining difference — everything else about ephemeral agents flows from that one extra step.
  • Environment drift is the hidden cost of persistence — long-lived agents need disciplined, ongoing maintenance to avoid it.
  • Ephemeral agents shift the maintenance burden to templates — the base image, not individual machines, needs to stay current.
  • Cost models differ fundamentally — persistent pays for idle time; ephemeral pays only for actual use.
  • Security profiles differ too — shared, reused machines carry more residual trust risk than freshly-provisioned, disposable ones.
  • Hybrid fleets are the pragmatic norm — most mature setups use both, matching each model to the workloads it fits best.