


Below are Declarative Pipeline examples showing common agent declarations inside a Jenkinsfile.
Example 1 — Run the pipeline on any available agent:
Best practice: set a root-level agent to provide sensible defaults for most stages, and override at the stage level when a specific environment is required (for example, a
nodejs Docker image or a windows agent). When using shell steps, reference the agent name with "$NODE_NAME" (or $NODE_NAME in POSIX shells) so the job output clearly indicates which node executed the step.See also: Jenkins Agents Documentation and Using Docker with Jenkins.