How do `agent` directives work (any, none, label, docker, kubernetes)?

IntermediateConceptJenkins
Answer

agent says where a pipeline or stage runs. agent any uses any available node. agent none at the top means no global agent, so each stage must declare its own (useful to avoid holding an executor during an input wait). agent { label 'x' } selects by label. agent { docker { image 'maven:3.9-eclipse-temurin-21' } } runs steps in a container on a Docker-capable node. agent { kubernetes { yaml '...' } } creates a pod from a spec.

pipeline {
  agent none
  stages {
    stage('Build') {
      agent { docker { image 'node:22' args '-v $HOME/.npm:/root/.npm' } }
      steps { sh 'npm ci && npm run build' }
    }
  }
}
All CI/CD questions

More on Jenkins