Why Docker agents?
- Clean environment every build
- Same image locally and in CI
- Node 18 and Node 20 jobs on one machine without conflicts
- Easy cleanup when the container exits
Example
pipeline {
agent none
stages {
stage('Test') {
agent {
docker {
image 'node:20-alpine'
args '--network host'
reuseNode true
}
}
steps {
sh 'node --version'
sh 'npm ci && npm test'
}
}
}
}The agent needs Docker available (Docker Pipeline plugin + Docker CLI on the node).
Use official language images (node:20, maven:3.9, golang:1.22) so toolchains stay consistent.