Check build logs and buildids from teamcity openApi?

hi new to teamcity....we run some command line scripts in teamcity..Each of the teamcity build has 1 script under it. After run of each script
and hence each build, I need to check for certain messages/string in that build's log and take action based on those log messages.

I went through teamcity api and found 3 necessary interfaces/classes:-

SBuildServer ----> BuildLookupService ---> BuildLogReader.

The problem is that SBuildServer requires many initilization parameters like buildid, buildnumber, buildtype.
How can I information about these parameters from teamcity?. Eg:- What is the parameter that keeps
track of last completed build or last failed build id.


thanks pavel for that link...I wrote a small class that just extends BuildServerAdapter, similar to one given in sample..Then , I created 1 xml
plugin file

<?xml version="1.0" encoding="UTF-8"?>
<beans default-autowire="constructor">
    <bean id="TCLlistener" init-method="register"/>

The class is as follows:-

* To change this template, choose Tools | Templates
* and open the template in the editor.
import jetbrains.buildServer.Build;
import jetbrains.buildServer.messages.Status;
import jetbrains.buildServer.serverSide.*;
import jetbrains.buildServer.users.User;
import jetbrains.buildServer.vcs.VcsModification;
import jetbrains.buildServer.vcs.VcsRoot;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

public class TCLlistener extends BuildServerAdapter {
     private  SBuildServer myBuildServer=null;
    public TCLlistener(SBuildServer sBuildServer) {
        System.out.println("TCL constructor");
        this.myBuildServer = sBuildServer;
    public void register(){
        System.out.println("TCL registered");
    public void agentRegistered(SBuildAgent sBuildAgent, long l) {
        System.out.println("Agent " + sBuildAgent.getName() + " registered");
    public void agentUnregistered(SBuildAgent sBuildAgent) {
        System.out.println("Agent " + sBuildAgent.getName() + " unregistered");
    public void agentRemoved(SBuildAgent sBuildAgent) {
        System.out.println("Agent " + sBuildAgent.getName() + " removed");
    public void buildTypeAddedToQueue(SBuildType buildTypeDescriptor) {
        System.out.println("Configuration  " + buildTypeDescriptor.getFullName() + " added to queue" + buildTypeDescriptor.getBuildTypeId());
    public void buildRemovedFromQueue(SQueuedBuild queuedBuild, User user, String comment) {
    public void buildQueueOrderChanged() {
        System.out.println("Build configurations order changed");
    public void buildTypeRegistered(SBuildType buildTypeDescriptor) {
        System.out.println("Configuration  " + buildTypeDescriptor.getFullName() + " registered" + buildTypeDescriptor.getBuildTypeId());
    public void buildTypeUnregistered(SBuildType buildTypeDescriptor) {
        System.out.println("Configuration  " + buildTypeDescriptor.getFullName() + " unregistered " + buildTypeDescriptor.getBuildTypeId());
    public void buildTypeActiveStatusChanged(SBuildType buildTypeDescriptor) {
        System.out.println("Configuration  " + buildTypeDescriptor.getFullName() + (buildTypeDescriptor.isPaused() ? " paused" : " unpaused") +  buildTypeDescriptor.getBuildTypeId());
    public void buildStarted(SRunningBuild sRunningBuild) {
        System.out.println("Sending buildStarted message");
        System.out.println("Build " + sRunningBuild.getFullName() + " started" + sRunningBuild);
    public void changesLoaded(SRunningBuild sRunningBuild) {
        System.out.println("Changes loaded for build " + sRunningBuild.getFullName() + sRunningBuild);
    public void buildChangedStatus(SRunningBuild sRunningBuild, Status status, Status status1) {
        System.out.println("Build " + sRunningBuild.getFullName() + " changed status" + sRunningBuild);
    public void buildFinished(SRunningBuild sRunningBuild) {
         System.out.println("Sending buildFinished message:" + sRunningBuild.getBuildStatus().getText());
        Status buildStatus = sRunningBuild.getBuildStatus();
        System.out.println("Build " + sRunningBuild.getFullName() + " finished" + sRunningBuild.getBuildStatus());
        System.out.println("Build " + sRunningBuild.getFullName() + " finished" + sRunningBuild);
    public void beforeBuildFinish(SRunningBuild sRunningBuild) {
        System.out.println("Build " + sRunningBuild.getFullName() + " is going to finish" + sRunningBuild);
    public void responsibleChanged(SBuildType sBuildType, ResponsibilityInfo responsibilityInfo, ResponsibilityInfo responsibilityInfo1, boolean b) {
        System.out.println("Responsible changed for " + sBuildType.getFullName() + sBuildType.getBuildTypeId());
    public void entryDeleted(SFinishedBuild sFinishedBuild) {
        System.out.println("Build " + sFinishedBuild.getFullName() + " deleted" + sFinishedBuild);
    public void projectCreated(String s) {
        System.out.println("Project " + s  +" created");
    public void projectRemoved(String s) {
        System.out.println("Project " + s  +" removed");
    public void buildInterrupted(SRunningBuild sRunningBuild) {
        System.out.println("Build " + sRunningBuild.getFullName() + " interrupted" + sRunningBuild);
    public void changeAdded(VcsModification vcsModification, VcsRoot vcsRoot) {
        System.out.println("Change added to " + vcsRoot.getName());
    public void agentStatusChanged(SBuildAgent sBuildAgent, boolean wasEnabled, final boolean wasAuthorized) {
        System.out.println("Agent " + sBuildAgent.getName() + " changed status");


       I created a zip folder with this class file and plugin xml and kept in <teamcity-home>\webapps\ROOT\WEB-INF\plugins.  After I stopped and restarted
       server, I was able to see plugin in .unpacked folder. Then I checked at teamcity-server log file.

      However, I was not able to find any sys.out println messages regarding this plugin in that log file. I am unable to understand the issue here. Why isnt this
      thing working?.My plugin is not getting registered...Can you please provide any tip on this. The only messages related to my plugin in log file were:-

[2009-01-05 11:23:28,709]   INFO - lugins.files.PluginJarSearcher - Visiting plugin dir: C:\TeamCity\webapps\ROOT\WEB-INF\plugins\.unpacked\TCLNEW
[2009-01-05 11:23:28,709]   INFO - s.loaders.PluginInfoLoaderImpl - Found server plugin file: C:\TeamCity\webapps\ROOT\WEB-INF\plugins\.unpacked\TCLNEW\TCLNEW.jar
[2009-01-05 11:23:28,709]   INFO - ns.classLoaders.OneClassLoader - Loaded classLoaders for Plugin TCLNEW@[Part@C:\TeamCity\webapps\ROOT\WEB-INF\plugins\.unpacked\TCLNEW\TCLNEW.jar,]
[2009-01-05 11:23:28,709]   INFO - .spring.SpringContextXmlFinder - Found spring config: META-INF/build-server-plugin-TCLNEW.xml
[2009-01-05 11:23:28,709]   INFO - gins.spring.SpringPluginLoader - Setting up plugin Application context on: [file:/C:/TeamCity/temp/TCLNEW50265spring.config.xml]

     Appreciate your help on this...


Could you please attach the whole zip file?

Pavel Sher



  To send messages to teamcity-server.log file you should use Log4J logging, and not system.out.println. System.out.println
  messages will appear only in TeamCity console and catalina.out file (if you have this file in TeamCity/logs directory).



pavel and kir...thanks for your help. Yes, i was late to realize all sys println messages were sent to tomcat console and
not in teamcity server file. However,  some of the messages did go to <TeamcityHome>/logs/stdout_date file. It seems that
the plugin is working okay.

However, I had few queries on it:-

"Teamcity build agent" and "Teamcity web server" services are not "enabled/on" always. Atleast, I have to manually
kick off 2nd service even though I have set it to "automatic" mode. The problem is that plugin is not working always.
One thing that I have noted is when the plugin is not working, I do not get a "stdout" file in logs. But teamcity works just fine.
Pl note that I have teamcity server and agent are installed on 1 machine.


Please sign in to leave a comment.