Howto create a custom notifier for TeamCity?
Information
Teamcity Documentation for Plugins: http://www.jetbrains.net/confluence/display/TCD3/Developing+TeamCity+Plugins
Another TeamCity Notifier Plugin: http://code.google.com/p/tcgrowl/
HowTo
First you need to download TeamCity. We are using the Professional Version which is free and can be used for up to 20 projects, 20 developers and 3 build agents. After installing TeamCity you can found the directory devPackage where the files openApi-help and openApi-source could be found. The sample project (samplePlugin.zip) contains some different plugins but no notifier example. For this one check out the source of http://code.google.com/p/buildbunny/source/browse/trunk/src/com/agimatec/nabaztag/teamcity/NabaztagNotificator.java or the [TcGrowl-Plugin http://code.google.com/p/tcgrowl/].
All libraries needed for compiling your plugin can be found in the folder TeamCity/webapps/ROOT/WEB-INF/lib.
To create your notifier plugin you just need to create your class which implements the Notificator interface. To get the notificator running you need to register it in the constructor. If you need parameters for your notifier you can pass a set of UserPropertyInfo.
``` public class NabaztagNotificator implements Notificator {
private static final String TYPE = "nabaztagNotifier";
private static final String TYPE_NAME = "Nabaztag Notifier";
private static final String NABAZTAG_RABBIT_ID = "rabbitId";
private static final String NABAZTAG_RABBIT_TOKEN = "rabbitToken";
private static final PropertyKey RABBIT_ID = new NotificatorPropertyKey(TYPE, NABAZTAG_RABBIT_ID);
private static final PropertyKey RABBIT_TOKEN = new NotificatorPropertyKey(TYPE, NABAZTAG_RABBIT_TOKEN);
public NabaztagNotificator(NotificatorRegistry notificatorRegistry) throws IOException {
ArrayList<UserPropertyInfo> userProps = new ArrayList<UserPropertyInfo>();
userProps.add(new UserPropertyInfo(NABAZTAG_RABBIT_ID, "Nabaztag Id"));
userProps.add(new UserPropertyInfo(NABAZTAG_RABBIT_TOKEN, "Nabaztag Token"));
notificatorRegistry.register(this, userProps);
}
public void notifyBuildSuccessful(SRunningBuild sRunningBuild, Set<SUser> sUsers) {
doNotifications("Build " + sRunningBuild.getFullName() + " successfull.",sUsers);
}
...
public String getNotificatorType() {
return TYPE;
}
public String getDisplayName() {
return TYPE_NAME;
}
public void doNotifications(String message, Set<SUser> sUsers) {
for(SUser user : sUsers) {
Nabaztag nabaztag = new Nabaztag();
nabaztag.setRabbitID(user.getPropertyValue(RABBIT_ID));
nabaztag.setToken(user.getPropertyValue(RABBIT_TOKEN));
nabaztag.setText(message);
nabaztag.publish();
}
}
}
```
To include the plugin in TeamCity you need to create the file build-server-plugin.xml: ```
```