

| Agent Type | Description | Use Case |
|---|---|---|
| Permanent Agents | Statically configured nodes always online, with pre-installed tools and fixed resources. | Stable builds with consistent toolchains |
| Docker Agents | Ephemeral containers created from custom images, destroyed after each build. | Isolation, reproducibility, version control |
| Cloud-Based Agents | On-demand VMs or Kubernetes Pods via cloud plugins (AWS, Azure, GCP). Auto-scaled per workload. | Elastic scaling and cost optimization |
| Label-Based Agents | Nodes tagged with labels (e.g., java, windows). Pipelines request labels instead of nodes. | Flexible matching based on node capabilities |
Declarative Pipeline Examples
Below are common Declarative Pipeline patterns for specifying agents in a Jenkinsfile.1. Any Available Agent
Useagent any to let Jenkins route the job to the next free executor:
2. Label-Based Agent
Specifyagent { label 'my-agent' } to target nodes matching a label:
Ensure that your Jenkins controller has at least one node configured with the
my-agent label. Otherwise, builds will remain queued.3. Docker Agent
Spin up a Docker container as your build environment. Here we mount the NPM cache for faster installs:Mounting host directories into containers can expose sensitive data. Validate
args parameters before use.4. Default and Stage-Specific Agents
Define a default agent at pipeline level and override it per stage:my-agent.