Ric*_*ich 10 hudson hudson-plugins
我们为Hudson提供了一个自定义插件,可以将构建的输出上传到远程计算机上.我们刚开始研究使用Hudson slave来提高构建的吞吐量,但是使用自定义插件的项目无法使用FileNotFoundExceptions进行部署.
从我们可以看到,即使构建发生在从属服务器上,插件也会在主服务器上运行.未找到的文件确实存在于从站上,但不存在于主站上.
问题:
Chr*_*Orr 18
首先,去詹金斯!;)
其次,你是对的 - 代码正在主服务器上执行.这是Hudson/Jenkins插件的默认行为.
当你想在远程节点上运行代码时,你需要获得对该节点的引用VirtualChannel,例如通过Launcher它可能传递到你的插件的main方法.
要在远程节点上运行的代码应封装在Callable- 这是需要可序列化的部分,因为Jenkins将自动序列化它,通过其通道将其传递给节点,执行它并返回结果.
这也隐藏了主服务器和从服务器之间的区别 - 即使构建实际上在主服务器上运行,"可调用"代码也将在正确的机器上透明地运行.
例如:
@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...
}
Run Code Online (Sandbox Code Playgroud)
另请参阅FileCallable,并查看具有类似功能的其他Jenkins插件的源代码.
我建议让你的插件正常工作,而不是使用网络共享解决方案.:)
| 归档时间: |
|
| 查看次数: |
4358 次 |
| 最近记录: |