0
0
JenkinsConceptBeginner · 3 min read

What is Agent None in Jenkins: Explanation and Usage

agent none in Jenkins pipeline means no default agent is allocated for the entire pipeline. It allows you to define agents only for specific stages, giving you more control over where and how your pipeline runs.
⚙️

How It Works

In Jenkins pipelines, an agent is like a worker that runs your tasks. Normally, you assign an agent at the pipeline level, so all stages run on that worker. But when you use agent none, you tell Jenkins not to assign any default worker for the whole pipeline.

This means you can pick and choose which stages get their own agents. Think of it like a team project where you don’t assign everyone to the same office; instead, each task can be done in a different place best suited for it. This saves resources and lets you run different parts of your pipeline on different machines or environments.

💻

Example

This example shows a Jenkins pipeline with agent none at the top level, and agents defined only for specific stages.

groovy
pipeline {
  agent none
  stages {
    stage('Build') {
      agent { label 'linux' }
      steps {
        echo 'Building on Linux agent'
      }
    }
    stage('Test') {
      agent { label 'windows' }
      steps {
        echo 'Testing on Windows agent'
      }
    }
  }
}
Output
[Pipeline] echo Building on Linux agent [Pipeline] echo Testing on Windows agent
🎯

When to Use

Use agent none when your pipeline needs different environments for different stages. For example, you might build your code on a Linux machine but run tests on Windows or Mac machines. This approach saves resources by not reserving an agent for the whole pipeline unnecessarily.

It is also useful when some stages do not require an agent at all, like simple script steps or notifications, so you avoid wasting worker time.

Key Points

  • agent none disables default agent allocation for the pipeline.
  • Agents must be specified at the stage level when using agent none.
  • Allows running different stages on different machines or environments.
  • Saves resources by not reserving an agent for the entire pipeline.

Key Takeaways

agent none means no default worker is assigned to the whole pipeline.
You must specify agents for individual stages when using agent none.
It helps run stages on different machines or environments efficiently.
Use it to save resources and customize where each stage runs.