Bird
Raised Fist0
Jenkinsdevops~20 mins

JDK configuration in Jenkins - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
JDK Configuration Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Jenkins JDK Configuration Verification
You have configured a JDK installation named 'jdk11' in Jenkins global tools. Which command run on a Jenkins agent will confirm the JDK version used by Jenkins?
Jenkins
$JAVA_HOME/bin/java -version
Awhich java
B$JAVA_HOME/bin/java -version
Cjava -version
Decho $PATH
Attempts:
2 left
💡 Hint
Check the JAVA_HOME environment variable set by Jenkins for the configured JDK.
❓ Configuration
intermediate
2:00remaining
Setting Up Multiple JDKs in Jenkins
You want to configure two JDK versions, JDK 8 and JDK 17, in Jenkins global tools. Which configuration snippet correctly defines both JDKs in Jenkins' config.xml?
A<jdk><name>jdk8</name><home>/usr/lib/jvm/java-8-openjdk</home></jdk><jdk><name>jdk17</name><home>/usr/lib/jvm/java-17-openjdk</home></jdk>
B<jdk><name>jdk8</name><home>/usr/lib/jvm/java-8-openjdk</home></jdk>
C<jdk><name>jdk8</name><home>/usr/lib/jvm/java-8-openjdk</home><jdk><name>jdk17</name><home>/usr/lib/jvm/java-17-openjdk</home></jdk></jdk>
D<jdk><name>jdk8</name><home>/usr/lib/jvm/java-8-openjdk</home></jdk><jdk17><name>jdk17</name><home>/usr/lib/jvm/java-17-openjdk</home></jdk17>
Attempts:
2 left
💡 Hint
Each JDK must be a separate element at the same level.
🔀 Workflow
advanced
3:00remaining
Using Multiple JDKs in Jenkins Pipeline
In a Jenkins pipeline, you want to run one stage with JDK 8 and another with JDK 17. Which pipeline snippet correctly switches JDK versions for each stage?
Jenkins
pipeline {
  agent any
  stages {
    stage('Build with JDK 8') {
      steps {
        // JDK 8 steps here
      }
    }
    stage('Build with JDK 17') {
      steps {
        // JDK 17 steps here
      }
    }
  }
}
A
pipeline {
  agent any
  stages {
    stage('Build with JDK 8') {
      steps {
        withEnv(['JAVA_HOME=${tool "jdk8"}', 'PATH+JAVA=${tool "jdk8"}/bin']) {
          sh 'java -version'
        }
      }
    }
    stage('Build with JDK 17') {
      steps {
        withEnv(['JAVA_HOME=${tool "jdk17"}', 'PATH+JAVA=${tool "jdk17"}/bin']) {
          sh 'java -version'
        }
      }
    }
  }
}
B
pipeline {
  agent any
  tools { jdk 'jdk8' }
  stages {
    stage('Build with JDK 8') {
      steps {
        sh 'java -version'
      }
    }
    stage('Build with JDK 17') {
      tools { jdk 'jdk17' }
      steps {
        sh 'java -version'
      }
    }
  }
}
C
pipeline {
  agent any
  stages {
    stage('Build with JDK 8') {
      tools { jdk 'jdk8' }
      steps {
        sh 'java -version'
      }
    }
    stage('Build with JDK 17') {
      tools { jdk 'jdk17' }
      steps {
        sh 'java -version'
      }
    }
  }
}
D
pipeline {
  agent any
  tools { jdk 'jdk8' }
  stages {
    stage('Build with JDK 8') {
      steps {
        sh 'java -version'
      }
    }
    stage('Build with JDK 17') {
      steps {
        sh 'JAVA_HOME=/usr/lib/jvm/java-17-openjdk java -version'
      }
    }
  }
}
Attempts:
2 left
💡 Hint
Use withEnv and tool step to switch JDK versions inside stages.
❓ Troubleshoot
advanced
2:00remaining
Jenkins JDK Configuration Not Applied
You configured JDK 11 in Jenkins global tools and selected it in a freestyle job, but the build still uses the system default JDK. What is the most likely cause?
AThe system default JDK overrides Jenkins JDK settings by design.
BThe Jenkins master needs a restart after adding a new JDK configuration.
CThe freestyle job must use a pipeline script to apply JDK settings.
DThe JDK installation is not marked as 'Install automatically' and the path is incorrect on the agent.
Attempts:
2 left
💡 Hint
Check if the JDK path is valid on the agent machine.
✅ Best Practice
expert
3:00remaining
Best Practice for Managing JDK Versions in Jenkins
Which approach is best to ensure consistent JDK versions across multiple Jenkins agents in a large environment?
ADo not configure JDK in Jenkins; rely on agents' default JDK installations.
BManually install JDKs on each agent and configure Jenkins to use local paths without automatic installation.
CConfigure JDK installations in Jenkins global tools with 'Install automatically' enabled using official JDK installers.
DUse environment variables on each agent to point to different JDKs and configure Jenkins to use system default.
Attempts:
2 left
💡 Hint
Automatic installation ensures uniformity and reduces manual errors.

Practice

(1/5)
1.

What is the main purpose of configuring JDK in Jenkins?

easy
A. To configure the Jenkins web interface theme
B. To set the Jenkins user password
C. To tell Jenkins where Java is installed
D. To install Jenkins plugins automatically

Solution

  1. Step 1: Understand JDK role in Jenkins

    Jenkins needs Java to run, so it must know where Java is installed.
  2. Step 2: Identify the purpose of JDK configuration

    Configuring JDK tells Jenkins the path to Java installations it can use.
  3. Final Answer:

    To tell Jenkins where Java is installed -> Option C
  4. Quick Check:

    JDK configuration = Java location [OK]
Hint: JDK config points Jenkins to Java location [OK]
Common Mistakes:
  • Confusing JDK config with user settings
  • Thinking JDK config installs plugins
  • Assuming JDK config changes UI appearance
2.

Which of the following is the correct way to add a new JDK in Jenkins global configuration?

1. Go to Manage Jenkins > Global Tool Configuration
2. Click 'Add JDK'
3. Enter a name and JAVA_HOME path
4. Save the configuration
easy
A. Add JDK under Manage Jenkins > Global Tool Configuration with name and path
B. Add JDK under Manage Jenkins > Configure System with only name
C. Add JDK under Manage Jenkins > Plugin Manager with JAVA_HOME path
D. Add JDK under Manage Jenkins > Credentials with name and path

Solution

  1. Step 1: Locate correct Jenkins menu

    JDKs are added under Manage Jenkins > Global Tool Configuration.
  2. Step 2: Confirm required fields

    You must provide a name and JAVA_HOME path to add a JDK.
  3. Final Answer:

    Add JDK under Manage Jenkins > Global Tool Configuration with name and path -> Option A
  4. Quick Check:

    JDK setup = Global Tool Configuration + name + path [OK]
Hint: Add JDK in Global Tool Configuration with name and path [OK]
Common Mistakes:
  • Trying to add JDK in Plugin Manager or Credentials
  • Skipping the JAVA_HOME path
  • Adding JDK under Configure System instead
3.

Given this Jenkins pipeline snippet, what JDK version will be used?

pipeline {
  agent any
  tools {
    jdk 'Java_11'
  }
  stages {
    stage('Build') {
      steps {
        sh 'java -version'
      }
    }
  }
}

Assuming Jenkins has JDKs configured as 'Java_8' and 'Java_11'.

medium
A. Java 8 version
B. Java 11 version
C. Default system Java version
D. No Java version, error occurs

Solution

  1. Step 1: Identify the JDK specified in pipeline

    The pipeline uses tools { jdk 'Java_11' } which selects the JDK named 'Java_11'.
  2. Step 2: Understand Jenkins tool usage

    Jenkins will use the configured JDK named 'Java_11' for the build steps.
  3. Final Answer:

    Java 11 version -> Option B
  4. Quick Check:

    tools jdk 'Java_11' = Java 11 used [OK]
Hint: Pipeline jdk name matches configured JDK used [OK]
Common Mistakes:
  • Assuming default system Java is used ignoring pipeline tools
  • Confusing JDK names with versions
  • Thinking error occurs if multiple JDKs exist
4.

What is wrong with this Jenkins JDK configuration snippet?

pipeline {
  agent any
  tools {
    jdk 'Java_15'
  }
  stages {
    stage('Test') {
      steps {
        sh 'java -version'
      }
    }
  }
}

Assuming Jenkins has only 'Java_8' and 'Java_11' configured.

medium
A. The pipeline syntax is invalid
B. The agent 'any' is not allowed with JDK tools
C. The shell command 'java -version' is incorrect
D. The JDK name 'Java_15' is not configured in Jenkins

Solution

  1. Step 1: Check configured JDK names

    Jenkins only has 'Java_8' and 'Java_11' configured, not 'Java_15'.
  2. Step 2: Understand pipeline tool usage

    Using a JDK name not configured causes Jenkins to fail to find the JDK.
  3. Final Answer:

    The JDK name 'Java_15' is not configured in Jenkins -> Option D
  4. Quick Check:

    JDK name must match configured names [OK]
Hint: JDK name must exist in Jenkins config [OK]
Common Mistakes:
  • Assuming pipeline syntax is wrong
  • Thinking shell command is invalid
  • Believing agent 'any' conflicts with JDK tools
5.

You want Jenkins to automatically install JDK 17 on agents that don't have it. Which configuration option should you use?

hard
A. Configure JDK with 'Install automatically' and select JDK 17 installer
B. Manually install JDK 17 on all agents and configure path in Jenkins
C. Use a shell script step to download and install JDK 17 during build
D. Set JAVA_HOME environment variable globally without JDK config

Solution

  1. Step 1: Understand Jenkins automatic JDK installation

    Jenkins can install JDK automatically if configured with 'Install automatically' option.
  2. Step 2: Choose correct configuration for JDK 17

    Selecting 'Install automatically' with JDK 17 installer lets Jenkins handle installation on agents.
  3. Final Answer:

    Configure JDK with 'Install automatically' and select JDK 17 installer -> Option A
  4. Quick Check:

    Automatic JDK install = 'Install automatically' option [OK]
Hint: Use 'Install automatically' to let Jenkins manage JDK installs [OK]
Common Mistakes:
  • Manually installing JDK on all agents is time-consuming
  • Using shell scripts adds complexity and errors
  • Setting JAVA_HOME alone doesn't install JDK
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard