1. 程式人生 > >[Jenkins] 設定jenkins節點時JDK環境導致異常

[Jenkins] 設定jenkins節點時JDK環境導致異常

之前的幾臺Jenkins Slave 都是OK的,最近新加一臺,卻在連線Slave時有下列沒有JDK 環境呢

Linux xmicnis 3.11.0-15-generic #25~precise1-Ubuntu SMP Thu Jan 30 17:39:31 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
Installing JDK [email protected]_Developer
Downloading JDK from http://download.oracle.com/otn/java/jdk/6u16-b01/jdk-6u16-linux-x64.bin
Oracle now requires Oracle account to download previous versions of JDK. Please specify your Oracle account username/password.
hudson.util.IOException2: Could not find any known supported java version in [java, /usr/bin/java, /usr/java/default/bin/java, /usr/java/latest/bin/java, /usr/local/bin/java, /usr/local/java/bin/java, /Dailybuild/Dailybuilds/jdk/bin/java], and we also failed to install JDK as a fallback
	at hudson.plugins.sshslaves.SSHLauncher.resolveJava(SSHLauncher.java:657)
	at hudson.plugins.sshslaves.SSHLauncher.launch(SSHLauncher.java:593)
	at hudson.slaves.SlaveComputer$1.call(SlaveComputer.java:243)
	at jenkins.util.ContextResettingExecutorService$2.call(ContextResettingExecutorService.java:46)
	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
	at java.util.concurrent.FutureTask.run(FutureTask.java:166)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:701)
Caused by: hudson.AbortException: Unable to install JDK unless a valid Oracle account username/password is provided in the system configuration.
	at hudson.tools.JDKInstaller.locate(JDKInstaller.java:426)
	at hudson.plugins.sshslaves.SSHLauncher.attemptToInstallJDK(SSHLauncher.java:764)
	at hudson.plugins.sshslaves.SSHLauncher.resolveJava(SSHLauncher.java:655)
	... 8 more
[04/29/15 09:06:16] [SSH] Connection closed.

很奇怪,系統中安裝了JDK了,為什麼會有這樣的問題呢。遠端登入伺服器 查看了一下
java -versionj<span style="white-space:pre">																		</span><span style="font-family: Arial, Helvetica, sans-serif;">J</span><span style="font-family: Arial, Helvetica, sans-serif;">ava version "1.7.0_75"                                                                                                                                                                                                                             </span><span style="font-family: Arial, Helvetica, sans-serif;">Java(TM) SE Runtime Environment (build 1.7.0_75-b13)<span style="white-space:pre">																					</span>      </span><span style="font-family: Arial, Helvetica, sans-serif;">Java HotSpot(TM) 64-Bit Server VM (build 24.75-b04, mixed mode)</span>

可是這就奇怪,換了個賬號試試
java version
java version "1.6.0_43"
Java(TM) SE Runtime Environment (build 1.6.0_43-b01)
Java HotSpot(TM) 64-Bit Server VM (build 20.14-b01, mixed mode)

兩個賬號下jdk 環境部一樣,想起來了當時這臺伺服器為了相容不同平臺的編譯,在裝JDK 時用了sun jdk1.6 和OPEN JDK 1.7,但是都是手動解壓包,沒有做連結。因為我當時自己加了兩個JDK系統環境變數在/etc/profile.d/jdk.sh,通過執行函式來設定當前環境變數鎮南關的JDK,感興趣可以參考《/etc/profile.d下新增環境變數》。

正常的情況下用apt-get 安裝完jdk 後會生成以下連結

/usr/bin/java -> /etc/alternatives/java
/etc/alternatives/java -> /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java

或者在有多個java 版本的情況下可以使用設定alternatives java 來更改java版本
update-alternatives --config java

解決方法:

          嘗試在~/.profile和~/.bashrc中加入環境變數,都失敗,因為載入這裡是需要使用者登入才可以的。

好在Jenkins 通過環境變數設定: