问题描述
我们有一个针对Hudson的自定义插件,该插件将内部版本的输出上传到远程计算机上.我们刚刚开始研究使用Hudson从站来提高构建的吞吐量,但是使用自定义插件的项目无法通过FileNotFoundExceptions进行部署.
We have a custom plugin for Hudson which uploads the output of a build onto a remote machine. We have just started looking into using a Hudson slave to improve throughput of builds, but the projects which use the custom plugin are failing to deploy with FileNotFoundExceptions.
从我们可以看到,即使在从属服务器上进行构建,该插件仍在主服务器上运行.找不到的文件确实存在于从属设备上,而没有存在于主文件上.
From what we can see, the plugin is being run on the master even when the build is happening on the slave. The file that is not being found does exist on the slave but not on the master.
问题:
- 插件可以在奴隶上运行吗?如果是这样,怎么办?有没有办法将插件标识为可序列化"?如果哈德森(Hudson)奴隶无法运行插件,那么SVN结帐如何发生?
- 这里的一些开发人员认为,解决此问题的方法是使Hudson主服务器的工作空间成为网络驱动器,并让从服务器使用相同的工作空间-这在我看来是个坏主意吗?
推荐答案
首先,去詹金斯! ;)
其次,您是正确的—该代码正在主服务器上执行.这是Hudson/Jenkins插件的默认行为.
Secondly, you are correct — the code is being executed on the master. This is the default behaviour of a Hudson/Jenkins plugin.
要在远程节点上运行代码时,需要获取对该节点的 VirtualChannel
,例如通过 Launcher
可能已传递到插件的主要方法中.
When you want to run code on a remote node, you need to get a reference to that node's VirtualChannel
, e.g. via the Launcher
that's probably passed into your plugin's main method.
要在远程节点上运行的代码应该封装在 Callable
—这是需要可序列化的部分,因为Jenkins会自动对其进行序列化,然后通过其通道将其传递给节点,然后执行并返回结果.
The code to be run on the remote node should be encapsulated in a Callable
— this is the part that needs to be serialisable, as Jenkins will automagically serialise it, pass it to the node via its channel, execute it and return the result.
这也隐藏了主从服务器之间的区别.即使该构建实际上在主数据库上运行,可调用"代码也将透明地在正确的计算机上运行.
This also hides the distinction between master and slave — even if the build is actually running on the master, the "callable" code will transparently run on the correct machine.
例如:
@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
,并查看源代码其他具有类似功能的Jenkins插件.
我建议您使插件正常工作,而不要使用网络共享解决方案..:)
I would recommend making your plugin work properly rather than using the network share solution.. :)
这篇关于哈德森奴隶可以运行插件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!