Search code examples
jenkinsjenkins-pipeline

How to install Java 11 through Jenkins Scripted pipeline?


I want to install Java 11 using scripted pipeline of Jenkins, and I have tried the below ways

node('MySlaves'){
   stage('TestStage'){
        println "ALm Exporter Started"
        tool name: '11.0.12', type: 'jdk'
       }
}

node('MySlaves'){
   environment {
    JAVA_HOME = tool name: '11.0.12', type: 'jdk'
    }

tools { 
        jdk '11.0.12'
    }

All the above 3 methods didn't help and if I use println "JAVA_HOME set : "+env.JAVA_HOME then I am getting the value of JDK1.8. Can someone let me know how can I install Java 11 (It is present in Custom tool) in Scripted pipeline ?


Solution

  • This shows how to do it:

    node {
      jdk = tool name: 'JDK17'
      env.JAVA_HOME = "${jdk}"
    
      echo "jdk installation path is: ${jdk}"
      [...]
    }