首先,go Jenkins! ;)
其次,你是正確的—該代碼正在主控上執行。這是Hudson/Jenkins插件的默認行爲。
當您想在遠程節點上運行代碼時,您需要獲得對該節點的引用,例如VirtualChannel
,例如,通過Launcher
這可能傳遞到您的插件的主要方法。
的代碼要被遠程節點應該以Callable
—被封裝上運行,這是一個需要serialisable的一部分,如詹金斯將自動地連載它,經由它的信道把它傳遞給節點,執行它和返回結果。
即使構建實際在主服務器上運行,這也隱藏了主從服務器—之間的區別,「可調用」代碼將透明地在正確的機器上運行。
例如:
@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
BuildListener listener) {
// This method is being run on the master...
// Define what should be run on the slave for this build
Callable<String, IOException> task = new Callable<String, IOException>() {
public String call() throws IOException {
// This code will run on the build slave
return InetAddress.getLocalHost().getHostName();
}
};
// Get a "channel" to the build machine and run the task there
String hostname = launcher.getChannel().call(task);
// Much success...
}
參見FileCallable
,並檢查了的other Jenkins plugins源代碼以類似的功能。
我會建議對你的插件正常工作,而不是使用網絡共享解決方案.. :)
+1「自動地」 – Cole9350 2014-04-29 16:02:20