TeamCity loads custom plugin, but there's no evidence the plugin code runs

PluginsTeamcity

Plugins Problem Overview


I am playing around with a TeamCity install and developing a plugin that extends a BuildServerAdapter. When I package it up and install it to the server, teamcity-server.log contains entries for my plugin:

  • found when scanning the plugins (.BuildServer\plugins) folder
  • registering agent plugin from server plugin
  • loads in the shared classloader
  • is loaded

The plugin is also listed on the plugins page in the server administration.

Beyond that...nothing. I've put in various log statements, via both the logger and System.out, and I don't see them. I've even added an exception into the constructor, and I see no evidence of that either in the system logs. When a build happens, there's again no evidence that my code is called.

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");
	}

...

The zip that I copy to .BuildServer\plugins has the following structure:

  • MyTeamCityPlugin.zip
    • teamcity.plugin.xml
    • server
    • MyTeamCityPlugin.jar
      • package folders containing class files
      • META-INF
        • build-server-plugin.xml
        • MANIFEST.MF

Looking at other plugins, they use the following structure, so I've tried that as well.

  • MyTeamCityPlugin.zip
    • MyTeamCityPlugin
      • teamcity.plugin.xml
      • MyTeamCityPlugin.jar
        • package folders containing class files
        • META-INF
          • build-server-plugin.xml
          • MANIFEST.MF

My build-server-plugin.xml contains the following:

<?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>

I'm part of the way there since the teamcity-server.log does indicate it knows about the plugin, and no longer throws an exception trying to load it. Unfortunately, not erring isn't the same working.

Using the ant build scripts from the sample plugin, I get the following error, so I've been packing things manually. This results in the seemingly successful load per above.

> Failed to initialize spring context for plugin MyTeamCityPlugin. Error creating bean with name 'simpleRunnerRunType': instantiation of bean failed.

Can anyone give me the kick I need to get this running correctly?

Plugins Solutions


Solution 1 - Plugins

The website describes it as being easy (yeah, if it works):

    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.

There is also online step-by-step guide on installing TeamCity plugin here.

Solution 2 - Plugins

You need to use the following code:

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

This will log to teamcity-server.log. Loggers class also contain other static fields like AUTH, VCS and so on. Each corresponds to separate log file (e.g. teamcity-vcs.log, teamcity-auth.log, etc.). In order to use this code you also need to add the following dependency in your pom.xml (for Maven):

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

This was tested with Teamcity 8.1.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRebecca ChernoffView Question on Stackoverflow
Solution 1 - PluginsWonderWorkerView Answer on Stackoverflow
Solution 2 - Pluginsvania-poohView Answer on Stackoverflow