Server Listener - buildTypeRegistered() called on server startup
Hi,
I have a plugin that extends BuildServerAdapter and does some action when a new build configuration is created in TeamCity by extending the buildTypeRegistered() method. Prior to TeamCity 5.0, this method was only called when a new build config was created, but after the upgrade it seems that it is being called when I start the server for all existing build configurations. Is this expected to happen with the upgrade, or did something break? If it is expected, is there another way I can achieve the functionality I used to have prior to the upgrade?
Here is a code snippet from my plugin:
public class MyListener extends BuildServerAdapter {
private final SBuildServer buildServer;
private final RunningBuildsManagerEx runningBuildsManager;
public MysListener(SBuildServer sBuildServer, RunningBuildsManagerEx runningBuildsManager) {
buildServer = sBuildServer;
this.runningBuildsManager = runningBuildsManager;
}
public void register(){
buildServer.addListener(this);
}
public void buildTypeRegistered(SBuildType buildType) {
//do some stuff here...
}
}
Thanks,
--Steve
Please sign in to leave a comment.
This change seems to be valid and it looks like a fix of an old bug. Anyway, if you need your code to work for newly registered build types only you can register your listener in serverStartup event (when all configuration settings are loaded). In this case your code will be compatible with previous versions of TeamCity too.
Can you show me how to register my listener in the serverStartup event? It seems I would already need another listener registered because until my listener is registered, how will it know when the serverStartup event has occurred?
Actually this is even simpler, leave your code as is, but add boolean field and set it to true if serverStartup event occurs. Then react to buildTypeRegistered events only if this field is true.
Okay, that solution works great. Thanks!