如何通过Jenkins脚本流程安装Java 11?

huangapple go评论45阅读模式
英文:

How to install Java 11 through Jenkins Scripted pipeline?

问题

我想使用Jenkins的脚本流程安装Java 11,我已经尝试了以下方式:

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'
}

以上三种方法都没有帮助,如果我使用 println "JAVA_HOME set : "+env.JAVA_HOME,那么我得到的是JDK1.8的值。请问有谁能告诉我如何在脚本流程中安装Java 11(它存在于自定义工具中)?

英文:

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 ?

答案1

得分: 0

这个 显示了如何执行它:

node {
  jdk = tool name: 'JDK17'
  env.JAVA_HOME = "${jdk}"

  echo "jdk 安装路径是: ${jdk}"
  [...]
}
英文:

This shows how to do it:

node {
  jdk = tool name: 'JDK17'
  env.JAVA_HOME = "${jdk}"

  echo "jdk installation path is: ${jdk}"
  [...]
}

huangapple
  • 本文由 发表于 2023年2月8日 14:20:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/75382010.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定