This Question is Answered

2 "helpful" answers available (2 pts)
4 Replies Last post: Jan 12, 2010 8:34 PM by Steve Chen  
Steve Chen Newbie 22 posts since
Mar 31, 2008
Currently Being Moderated

Jan 11, 2010 10:00 PM

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

Pavel Sher JetBrains 2,148 posts since
Mar 6, 2008
Currently Being Moderated
Jan 12, 2010 2:17 AM in response to: Steve Chen
Re: Server Listener - buildTypeRegistered() called on server startup

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.

Pavel Sher JetBrains 2,148 posts since
Mar 6, 2008
Currently Being Moderated
Jan 12, 2010 11:55 AM in response to: Steve Chen
Re: Server Listener - buildTypeRegistered() called on server startup

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.

More Like This

  • Retrieving data ...