Tools Directive for Build Tools
What You'll Learn
You'll learn how to use Jenkins' tools directive to automatically install and configure build tools like Maven, JDK, Gradle, and Node.js in your pipeline without manual setup.
Why the Tools Directive Matters
Imagine showing up to a construction site where every tool you need—hammers, drills, saws—is already laid out and ready to use. That's what the tools directive does for your Jenkins pipeline. Instead of manually configuring paths or worrying about which agent has which tool installed, you declare what you need and Jenkins handles the rest.
How It Works
The tools directive appears inside a stage or at the pipeline level, specifying which pre-configured tools your build requires. Jenkins automatically locates the tool (configured in Manage Jenkins → Global Tool Configuration), adds it to the PATH, and sets relevant environment variables.
pipeline {
agent any
tools {
maven 'Maven-3.8.6'
jdk 'JDK-17'
}
stages {
stage('Build') {
steps {
sh 'mvn clean package'
}
}
}
}
In this example, Jenkins automatically configures Maven 3.8.6 and JDK 17 (names matching your Global Tool Configuration) before executing any build steps. The mvn command just works—no path manipulation needed.
Common Tools
jdk: Java Development Kit versionsmaven: Apache Mavengradle: Gradle build toolnodejs: Node.js runtime
Each tool must be pre-configured in Jenkins with a name you reference in your pipeline.
Key Takeaway: The tools directive automatically provisions and configures build tools for your pipeline stages, eliminating manual environment setup and ensuring consistent build environments across different agents.