Java 如何为 Jenkins 工作更改 JDK?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28810477/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change the JDK for a Jenkins job?
提问by GuruKulki
I have imported the jenkins jobs from existing jenkins server from another machine. But the problem is, it has the JDK referenced as per the old machines and I want to change it to use the JDK configured in my new jenkins. But I am unable to find any way of doing this. So, please if you have come across this situation and found a way then please help me too.
我已经从另一台机器上的现有 jenkins 服务器导入了 jenkins 作业。但问题是,它根据旧机器引用了 JDK,我想将其更改为使用我的新 jenkins 中配置的 JDK。但我无法找到任何方法来做到这一点。因此,如果您遇到这种情况并找到了方法,请也请帮助我。
Thanks.
谢谢。
采纳答案by nomis
There is a JDK dropdown in "job name" -> Configure in Jenkins web ui. It will list all JDKs available in Jenkins configuration.
“作业名称”中有一个 JDK 下拉列表 -> Jenkins web ui 中的配置。它将列出 Jenkins 配置中可用的所有 JDK。
回答by Iker Aguayo
Here is where you should configure in your job:
这是您应该在作业中配置的位置:
In JDK there is the combobox with the different JDK configured in your Jenkins.
在 JDK 中有一个组合框,其中包含在 Jenkins 中配置的不同 JDK。
Here is where you should configure in the config of your Jenkins:
这是您应该在 Jenkins 的配置中配置的位置:
回答by dymy
Here is my experience with Jenkins version 1.636: as long as I have only one "Install automatically" JDK configured in Jenkins JDK section, I don't see "JDK" dropdown in Job=>Configure section, but as soon as I added second JDK in Jenkins config, JDK dropdown appeared in Job=>Configure section with 3 options [(System), JDK1, JDK2]
这是我使用 Jenkins 1.636 版的经验:只要我在 Jenkins JDK 部分中只配置了一个“自动安装”JDK,我就不会在 Job=>Configure 部分看到“JDK”下拉列表,但是一旦我添加了第二个Jenkins 配置中的 JDK,JDK 下拉列表出现在 Job=>Configure 部分,有 3 个选项 [(System), JDK1, JDK2]
回答by AntuanSoft
Be careful with jobs
工作要小心
1 - if you have a job based in maven, Jenkins takes your default java configuration and you decide the compilation level in your POM.XML.
1 - 如果您有一份基于 maven 的工作,Jenkins 会采用您的默认 Java 配置,并由您决定 POM.XML 中的编译级别。
2 - if you have a free style job, in the the configuration option of the job you can select the JDK that you want to use.
2 - 如果你有一个自由风格的作业,在作业的配置选项中你可以选择你想要使用的 JDK。
Hope this help.
希望这有帮助。
回答by RZet
For existing jobs you're editing, the JDK drop-down choice may not be available if you've just added a single JDK config in the 'Configure System' Jenkins settings.
对于您正在编辑的现有作业,如果您刚刚在“配置系统”Jenkins 设置中添加了单个 JDK 配置,则 JDK 下拉选项可能不可用。
However, it is available for new jobs.
但是,它适用于新工作。
Surprisingly, if you add a second JDK config, it becomes available in an existing job too.
令人惊讶的是,如果您添加第二个 JDK 配置,它也会在现有作业中可用。
This looks to me like a bug (tested in Jenkins ver. 1.629).
这在我看来就像一个错误(在 Jenkins 版本 1.629 中测试)。
See a similar issue raised here: JDK selection is hidden even when a JDK is configured
请参阅此处提出的类似问题:即使配置了 JDK,也隐藏了 JDK 选择
回答by Jitesh Sojitra
Using latest Jenkins version 2.7.4 which is also having a bug for existing jobs.
使用最新的 Jenkins 版本 2.7.4,该版本对现有作业也存在错误。
Add new JDKs through Manage Jenkins -> Global Tool Configuration -> JDK ** If you edit current job then JDK dropdown is not showing (bug)
Hit http://your_jenkin_server:8080/restartand restart the server
Re-configure job
通过管理 Jenkins -> 全局工具配置 -> JDK 添加新的 JDK ** 如果您编辑当前作业,则 JDK 下拉列表不显示(错误)
重新配置作业
Now, you should see JDK dropdown in "job name" -> Configure in Jenkins web ui. It will list all JDKs available in Jenkins configuration.
现在,您应该在 Jenkins web ui 中的“作业名称”-> 配置中看到 JDK 下拉列表。它将列出 Jenkins 配置中可用的所有 JDK。
回答by Gennadiy Ryabkin
For those who couldn't find this option. Install JDK Parameter Plugin
对于那些找不到此选项的人。安装JDK 参数插件
回答by Horst Krause
If you have a multi-config (matrix) job, you do not have a JDK dropdown but need to configure the jdk as build axis.
如果您有一个多配置(矩阵)作业,则没有 JDK 下拉列表,但需要将 jdk 配置为构建轴。