Interview Prep/Jenkins/Declarative pipeline syntax

What does the `tools` directive do?

BeginnerConceptDeclarative pipeline syntax
Answer

It installs (if needed) and puts on PATH a tool configured globally under Tools, such as a JDK, Maven or NodeJS installation.

tools { jdk 'temurin-21'; maven 'maven-3.9' }

The name must match the global tool configuration (often set via JCasC). With container-based agents we usually skip tools and pick an image that already contains the right versions, which is faster and reproducible.

All Jenkins questions Roadmap: Jenkins

More on Declarative pipeline syntax