Listener must register in util.EventDispatcher?

Agent side events

There is jetbrains.buildServer.agent.AgentLifeCycleListener interface and corresponding adapter class jetbrains.buildServer.agent.AgentLifeCycleAdapter which can be used to receive notifications about agent side events, like starting of the build, build finishing and so on. Your listener must be registered in the jetbrains.buildServer.util.EventDispatcher. This service is also defined in the Spring context.


This is from the teamcity plugin development documentation. I don't know what is meant by the part in red above. Also the link that is in that red part is broken so it makes it even harder to learn what is meant by this sentence. Ultimately I am just trying to extend AgentLifeCycleAdapter to get access to information about the agent side events. If someone could help me understand what is meant by the above I would really appreciate it. Thanks.

Tom

6 comments
Comment actions Permalink

Indeed there were no javadoc for EventDispatcher class, thank you for pointing that.
To register your listener in the agent plugin you should do the following:
- ask for EventDispatcher<AgentLifeCycleListener> instance in the class constructor (instance will be provided automatically when your class is instantiated)
- call addListener(<your listener>) method of the obtained event dispatcher class

0
Comment actions Permalink

Hi thanks for writing me back so quick . Ok I am sorry if I am being dumb with this, but do you mean like this? Also congrats on the 1000 posts, I just noticed that.


import jetbrains.buildServer.agent.AgentLifeCycleAdapter;
import jetbrains.buildServer.agent.AgentLifeCycleListener;
import jetbrains.buildServer.serverSide.SBuildAgent;

public class AgentBuildInformation extends AgentLifeCycleAdapter{
    private final AgentLifeCycleListener agentLifeCycleListner;
    public AgentBuildInformation(AgentLifeCycleListener agentLifeCycleListner){
        this.agentLifeCycleListner = agentLifeCycleListner;

     }
}


If I run the above I get this error:

java.lang.NoClassDefFoundError: jetbrains/buildServer/agent/AgentLifeCycleAdapter

Thanks again,
Tom

0
Comment actions Permalink

Where do you plan to use this plugin? On agent or on the server side? I am asking because your class imports jetbrains.buildServer.serverSide.SBuildAgent but this interface is only available on the server (note the S prefix). So if you tried to use this code on the server side then the error is correct because jetbrains.buildServer.agent.AgentLifeCycleAdapter is only available on the agent.

Could you please describe what kind of plugin you would like to create?

0
Comment actions Permalink

Hi Pavel,

I see what you are saying with the import of jetbrains.buildServer.serverSide.SBuildAgen, but it was just that, only an import. It was never implemented in that example, I just forgot to delete it before I posted that small bit of code. Still I tried deleting it and restarted the server. I still get the same message

nested exception is java.lang.NoClassDefFoundError: jetbrains/buildServer/agent/AgentLifeCycleAdapter

Really though what I am hoping to achieve is this. I am wanting to take a class that extends BuildServerAdapter (similar to how TeamCityLoggingListener from the sample plugin does). This allows me to listen for all of the server side events like buildCreated, buildStarted ect. TeamCityLoggingListener listens for these events too and logs it to it's own custom log like this:

addToLog("Build " + sRunningBuild.getFullName() + " started", sRunningBuild);

and then the log gets displayed in it's own custom tab later. I want to do this too except that I don't want the above outputted to a custom log I want it outputted to a .txt file that gets thrown into the artifacts directory with the other artifacts. I am having trouble seeing how to create and write to a file that will be outputted in the artifacts directory. Is this possible from this one class that extends BuildServerAdapter or am I going about it in the wrong way?

Thanks for getting back to me,
Tom

0
Comment actions Permalink

Ok, it is clear now that you are writing server side plugin. Then you should remove references to AgentLifeCycleAdapter because as I mentioned earlier there is no such class on the server. On the server side you should extend your listener from BuildServerAdapter class.

Build artifacts directory you can obtain using SBuild::getArtifactsDirectory() method. You can create files in this directory and they will be shown in the build artifacts automatically.

Hope this helps.

0
Comment actions Permalink

Thanks Pavel got this all straightened out. Appreciate your help.

0

Please sign in to leave a comment.