Hudson奴隶可以运行插件吗?

Ric*_*ich 10 hudson hudson-plugins

我们为Hudson提供了一个自定义插件,可以将构建的输出上传到远程计算机上.我们刚开始研究使用Hudson slave来提高构建的吞吐量,但是使用自定义插件的项目无法使用FileNotFoundExceptions进行部署.

从我们可以看到,即使构建发生在从属服务器上,插件也会在主服务器上运行.未找到的文件确实存在于从站上,但不存在于主站上.

问题:

  1. 插件可以在奴隶上运行吗?如果是这样,怎么样?有没有办法将插件识别为"可序列化"?如果Hudson奴隶无法运行插件,那么SVN结账会如何发生?
  2. 这里的一些开发人员认为解决这个问题的方法是让Hudson master的工作区成为一个网络驱动器,让奴隶使用相同的工作空间 - 这对我来说是不是很糟糕?

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插件的源代码.

我建议让你的插件正常工作,而不是使用网络共享解决方案.:)