0
0
Jenkinsdevops~20 mins

JDK configuration in Jenkins - Practice Problems & Coding Challenges

Choose your learning style9 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.