【问题标题】:TeamCity loads custom plugin, but there's no evidence the plugin code runsTeamCity 加载自定义插件,但没有证据表明插件代码运行
【发布时间】:2012-01-22 19:35:27
【问题描述】:

我正在玩 TeamCity 安装并开发一个扩展 BuildServerAdapter 的插件。当我将它打包并安装到服务器时,teamcity-server.log 包含我的插件的条目:

  • 在扫描插件 (.BuildServer\plugins) 文件夹时发现
  • 从服务器插件注册代理插件
  • 在共享类加载器中加载
  • 已加载

该插件也列在服务器管理的插件页面上。

除此之外……什么都没有。我已经通过记录器和 System.out 输入了各种日志语句,但我没有看到它们。我什至在构造函数中添加了一个异常,我在系统日志中也没有看到任何证据。当构建发生时,再次没有证据表明我的代码被调用了。

public class CustomBuildServerAdapter extends BuildServerAdapter {

    private SBuildServer myBuildServer;
    private static final Logger LOG = Logger.getLogger(CustomBuildServerAdapter.class);

    private void debug(String msg) { LOG.debug(msg); System.out.println(msg); }

    public CustomBuildServerAdapter(SBuildServer aBuildServer) throws Exception {
        throw new Exception("constructor is being called, at least we know that...");

        //myBuildServer = aBuildServer;
        //debug("constructor");
    }

    public void register() {
        debug("registering");
        myBuildServer.addListener(this);
        debug("registered");
    }

    public void buildFinished(SRunningBuild build) {
        debug("build finished");
        postMessage(build.getFullName() + " - " + build.getStatusDescriptor().getText());
        debug("message posted");
    }

...

我复制到 .BuildServer\plugins 的 zip 具有以下结构:

  • MyTeamCityPlugin.zip
    • teamcity.plugin.xml
    • 服务器
    • MyTeamCityPlugin.jar
      • 包含类文件的包文件夹
      • 元信息
        • build-server-plugin.xml
        • 清单.MF

查看其他插件,他们使用以下结构,所以我也尝试过。

  • MyTeamCityPlugin.zip
    • 我的团队城市插件
      • teamcity.plugin.xml
      • MyTeamCityPlugin.jar
        • 包含类文件的包文件夹
        • 元信息
          • build-server-plugin.xml
          • 清单.MF

我的 build-server-plugin.xml 包含以下内容:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans default-autowire="constructor">
    <bean id="myplugin" class="com.blah.blah.blah.CustomBuildServerAdapter" init-method="register"/>
</beans>

我是其中的一部分,因为 teamcity-server.log 确实表明它知道插件,并且不再抛出试图加载它的异常。不幸的是,不犯错是不一样的工作。

使用示例插件中的 ant 构建脚本,我收到以下错误,所以我一直在手动打包。这导致上述看似成功的加载。

无法为插件 MyTeamCityPlugin 初始化 spring 上下文。创建名为“simpleRunnerRunType”的 bean 时出错:bean 实例化失败。

任何人都可以给予我正确运行所需的帮助吗?

【问题讨论】:

  • 如果您的插件列在插件页面(管理 -> 服务器配置),那么您的类已加载并初始化。您如何检查插件是否正常工作?通过查看服务器日志?但在这种情况下,您需要使用 info 或 warn 优先级记录,因为默认情况下禁用调试。
  • 万一 stdout/err 在内部被重定向...也许尝试发送电子邮件,创建一些虚拟文件。尝试使用那些老式的基本调试技术。

标签: plugins teamcity


【解决方案1】:

该网站将其描述为简单(是的,如果可行的话):

    1. Shut down TeamCity server.
    2. Copy the zip archive with the plugin to <TeamCity Data Directory>/plugins.
    3. Start the TeamCity server: the plugin files will be unpacked and processed automatically.

还有关于安装 TeamCity 插件here 的在线分步指南。

【讨论】:

    【解决方案2】:

    您需要使用以下代码:

    Loggers.SERVER.info("Your message");
    

    这将记录到 teamcity-server.log。 Loggers 类还包含其他静态字段,如 AUTH、VCS 等。每个对应于单独的日志文件(例如 teamcity-vcs.log、teamcity-auth.log 等)。为了使用此代码,您还需要在 pom.xml(对于 Maven)中添加以下依赖项:

    <dependency>
      <groupId>com.intellij</groupId>
      <artifactId>openapi</artifactId>
      <version>7.0.3</version>
      <scope>provided</scope>
    </dependency>
    

    这是使用 Teamcity 8.1 测试的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-17
      • 2017-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多