我们为Hudson提供了一个自定义插件,可将构建的输出上传到远程计算机上。我们刚刚开始研究使用Hudson从属服务器来提高构建的吞吐量,但是使用自定义插件的项目无法通过FileNotFoundExceptions进行部署。
从我们可以看到,即使在从属服务器上进行构建,该插件仍在主服务器上运行。找不到的文件确实存在于从属设备上,但没有存在于主文件上。
问题:
最佳答案
首先,go Jenkins! ;)
其次,您是正确的-代码正在主服务器上执行。这是Hudson/Jenkins插件的默认行为。
当您想在远程节点上运行代码时,您需要获取对该节点的 VirtualChannel
的引用,例如通过 Launcher
可能已传递到插件的main方法中。
要在远程节点上运行的代码应该封装在 Callable
中-这是需要可序列化的部分,因为Jenkins会自动对其进行序列化,然后通过其 channel 传递给节点,执行并返回结果。
这也隐藏了主服务器和从服务器之间的区别-即使该构建实际上在主服务器上运行,“可调用”代码也将透明地在正确的计算机上运行。
例如:
@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的源代码。我建议您使您的插件正常工作,而不要使用网络共享解决方案.. :)
关于hudson - hudson 奴隶可以运行插件吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9279898/