0
0
Jenkinsdevops~15 mins

Tools directive in Jenkins - Mini Project: Build & Apply

Choose your learning style9 modes available
Using Jenkins Tools Directive
📖 Scenario: You are setting up a Jenkins pipeline to build a Java project. Jenkins needs to use a specific JDK version installed on the server.
🎯 Goal: Learn how to use the tools directive in a Jenkins pipeline to specify the JDK version for your build.
📋 What You'll Learn
Create a Jenkins pipeline script
Use the tools directive to specify JDK 11
Print the Java version to verify the correct JDK is used
💡 Why This Matters
🌍 Real World
In real projects, Jenkins pipelines often need specific tools like JDKs or build tools. The <code>tools</code> directive helps Jenkins pick the right versions automatically.
💼 Career
Knowing how to configure Jenkins pipelines with the correct tools is essential for DevOps engineers and automation specialists to ensure consistent builds.
Progress0 / 4 steps
1
Create a basic Jenkins pipeline
Write a Jenkins pipeline script with a pipeline block and an empty agent any section.
Jenkins
Need a hint?

Start with the basic pipeline structure including pipeline and agent any.

2
Add the tools directive to specify JDK 11
Inside the pipeline block, add a tools directive specifying jdk 'JDK11' to use JDK 11.
Jenkins
Need a hint?

Use the tools block and specify jdk 'JDK11' exactly.

3
Add a stage to print the Java version
Add a stage named 'Check Java' with a steps block that runs the shell command java -version.
Jenkins
Need a hint?

Use stages block with a stage named 'Check Java'. Inside steps, run sh 'java -version'.

4
Print the Java version output
Run the pipeline and ensure the console output shows the Java version starting with openjdk version "11.
Jenkins
Need a hint?

Look at the Jenkins console output after running the pipeline. It should show the Java version starting with openjdk version "11.