0
0
Jenkinsdevops~20 mins

Tools directive in Jenkins - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Tools Directive Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Jenkins Tools Directive Usage Output
What is the output of this Jenkins pipeline snippet using the tools directive?

pipeline {
  agent any
  tools {
    maven 'Maven_3.8.1'
  }
  stages {
    stage('Build') {
      steps {
        sh 'mvn -version'
      }
    }
  }
}
Jenkins
pipeline {
  agent any
  tools {
    maven 'Maven_3.8.1'
  }
  stages {
    stage('Build') {
      steps {
        sh 'mvn -version'
      }
    }
  }
}
AThe pipeline fails with 'mvn: command not found' error
BThe pipeline skips the build stage without error
CThe pipeline runs but prints Java version instead of Maven
DThe pipeline runs and prints Maven version 3.8.1 details
Attempts:
2 left
💡 Hint
The tools directive sets up the specified tool version in the environment.
Configuration
intermediate
2:00remaining
Correct Tools Directive Syntax
Which Jenkins pipeline snippet correctly uses the tools directive to set JDK 11 and Maven 3.6.3?
Atools { jdk 'JDK11' maven 'Maven_3.6.3' }
Btools { jdk: 'JDK11', maven: 'Maven_3.6.3' }
Ctools { jdk 'JDK11'; maven 'Maven_3.6.3' }
Dtools { jdk = 'JDK11'; maven = 'Maven_3.6.3' }
Attempts:
2 left
💡 Hint
The tools directive uses Groovy method call syntax without colons or equals.
Troubleshoot
advanced
2:00remaining
Troubleshooting Tools Directive Failure
A Jenkins pipeline with tools { maven 'Maven_3.8.1' } fails with:

ERROR: Maven tool 'Maven_3.8.1' is not configured

What is the most likely cause?
AThe Jenkinsfile is missing the <code>agent any</code> directive
BThe Jenkins agent does not have Maven installed locally
CThe Maven installation named 'Maven_3.8.1' is not defined in Jenkins global tool configuration
DThe pipeline syntax is incorrect and causes the tools directive to be ignored
Attempts:
2 left
💡 Hint
Check Jenkins global tool configuration for the named tool installation.
🔀 Workflow
advanced
2:00remaining
Tools Directive Effect on Environment Variables
In a Jenkins pipeline using tools { jdk 'JDK11' }, which environment variable is automatically set for the build steps?
APATH including the Maven bin directory
BJAVA_HOME pointing to the JDK11 installation path
CMAVEN_HOME pointing to the Maven installation
DJDK_HOME pointing to the JDK8 installation path
Attempts:
2 left
💡 Hint
The tools directive sets environment variables related to the tool used.
Best Practice
expert
2:00remaining
Best Practice for Using Tools Directive in Shared Libraries
You maintain a Jenkins shared library that runs builds requiring Maven. What is the best practice to ensure the tools directive works correctly when used inside the shared library's pipeline code?
ADefine the required tools in the Jenkinsfile that calls the shared library, not inside the library code
BHardcode the tools directive inside the shared library with fixed tool names
CUse environment variables to manually set tool paths inside the shared library
DAvoid using the tools directive and install tools manually on agents
Attempts:
2 left
💡 Hint
Consider how Jenkins processes the tools directive in pipeline and shared library contexts.