Global Tool Configuration

Global tools let Jenkins auto-install and manage build tools like JDK, Maven, Node.js, and Git.

Syntaxtools { 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

  1. Go to Manage Jenkins > Tools.
  2. Add a tool installation, give it a name, and choose 'Install automatically'.
  3. Reference the named tool in your pipeline with the tool step.

Benefits

  • Consistent tool versions across all agents.
  • Automatic download on first use.
  • Easy to test multiple versions side by side.

Example

Example · bash
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.

Example · groovy
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.

Example · groovy
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.

Example · yaml
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

  • Be the first to comment on this lesson.