【问题标题】:Can Hudson slaves run plugins?哈德逊奴隶可以运行插件吗?
【发布时间】:2012-03-05 23:58:08
【问题描述】:

我们有一个用于 Hudson 的自定义插件,它将构建的输出上传到远程机器上。我们刚刚开始研究使用 Hudson 从站来提高构建的吞吐量,但是使用自定义插件的项目无法通过 FileNotFoundExceptions 进行部署。

从我们所见,插件在主服务器上运行,即使构建是在从服务器上进行的。未找到的文件确实存在于从属服务器上,但在主服务器上不存在。

问题:

  1. 插件可以在slave上运行吗?如果是这样,怎么做?有没有办法将插件识别为“可序列化”?如果 Hudson slave 不能运行插件,SVN checkout 是怎么发生的?
  2. 这里的一些开发人员认为,解决这个问题的方法是让 Hudson 主工作区成为网络驱动器,让从站使用同一个工作区 - 这在我看来是不是很糟糕?

【问题讨论】:

    标签: hudson hudson-plugins


    【解决方案1】:

    首先,go Jenkins! ;)

    其次,你是对的——代码是在主服务器上执行的。这是 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...
    }
    

    另请参阅FileCallable,并查看具有类似功能的other Jenkins plugins 的源代码。

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

    【讨论】:

      猜你喜欢
      • 2010-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多