Global Tool Configuration
Global tools let Jenkins auto-install and manage build tools like JDK, Maven, Node.js, and Git.
Syntax
tools { maven 'Maven-3.9'; jdk 'JDK-17' }Your builds need tools — a JDK, Maven, Node.js, Git. Rather than installing these by hand on every agent, Jenkins can manage them centrally through Global Tool Configuration.
How it works
- Go to Manage Jenkins > Tools.
- Add a tool installation, give it a name, and choose 'Install automatically'.
- Reference the named tool in your pipeline with the
toolstep.
Benefits
- Consistent tool versions across all agents.
- Automatic download on first use.
- Easy to test multiple versions side by side.
Example
pipeline {
agent any
tools {
maven 'Maven-3.9'
jdk 'JDK-17'
}
stages {
stage('Build') {
steps {
sh 'mvn --version'
sh 'mvn clean package'
}
}
}
}When to use it
- Jenkins auto-installs a specific JDK version on each agent on demand so builds always use the correct Java version.
- A team configures a named Maven installation so pipelines can reference it by name without hard-coding the path.
- Node.js is configured as a global tool with nvm so pipelines can switch Node versions per project without agent setup.
More examples
Use Maven tool in pipeline
References named Maven and JDK installations from Global Tool Configuration using the tools block.
pipeline {
agent any
tools {
maven 'Maven-3.9' // name configured in Global Tool Configuration
jdk 'JDK-21'
}
stages {
stage('Build') {
steps { sh 'mvn clean package' }
}
}
}Node.js tool installation
Uses the NodeJS plugin's global tool to make a specific Node.js version available in the pipeline.
pipeline {
agent any
tools {
nodejs 'NodeJS-20' // requires NodeJS plugin
}
stages {
stage('Install & Test') {
steps {
sh 'node --version'
sh 'npm ci && npm test'
}
}
}
}Global tool config via JCasC
Defines Maven and JDK global tool installations in JCasC YAML so they are provisioned automatically on first boot.
tool:
maven:
installations:
- name: Maven-3.9
properties:
- installSource:
installers:
- maven:
id: '3.9.6'
jdk:
installations:
- name: JDK-21
properties:
- installSource:
installers:
- adoptOpenJdkInstaller:
id: 'jdk-21.0.3+9'
Discussion