Agent Configuration and Labels
What You'll Learn
You'll learn how to configure Jenkins agents with labels and properties to intelligently route jobs to the right build machines based on capabilities and requirements.
Core Concept
In Jenkins' distributed build architecture, labels act as tags that identify what an agent can do. Think of them like skill badges on a resume—they tell Jenkins which agent has the right tools, operating system, or resources to run a particular job.
When you configure an agent (a machine that executes builds), you assign it one or more labels such as linux, docker, python3.9, or high-memory. Then, in your pipeline's agent directive, you specify which label your job needs. Jenkins automatically routes the job to any available agent that matches.
Why This Matters
Without labels, you'd have to hardcode specific agent names in every pipeline. Labels provide flexibility: if you have five Linux machines with Docker installed, you can label them all docker-linux and let Jenkins pick whichever is free. This improves resource utilization and makes your infrastructure more scalable.
Configuration Example (Conceptual)
In Jenkins, you'd navigate to an agent's configuration page and add labels in the designated field:
- Agent Name:
build-server-01 - Labels:
linux ubuntu docker java11
In your pipeline, you reference the label:
agent { label 'linux && docker' }
This tells Jenkins: "Run this job on any agent that has BOTH the linux AND docker labels."
You can also configure agent properties like the number of executors (parallel job slots), workspace paths, and environment variables specific to that machine.
Key Takeaway: Labels transform agents from rigid, named resources into a flexible pool of capabilities, allowing Jenkins to dynamically match jobs with suitable build environments based on requirements rather than hardcoded machine names.