Notificator
First, congratultions on a good product.
Im writing a notificator for our internal chat (not Jabber).
I looked at http://www.jetbrains.net/confluence/display/TW/PluginDevelopment+ but this now seems to be out of date.
Then I looked at the Jabber notifier and that pointed me in the right direction.
Id really like to see some JavaDoc for jetbrains.buildServer.notification.Notificator but I cant find it. Im guessing I need to register the Notificator with the server.
Also, I cant find a useful feature that was in CruiseControl - 'first sucessful build after failure' - obviously this is useful so I dont spam with succeeding or failing builds.
Kindest regards,
Andrew.
Please sign in to leave a comment.
Hi Andrew,
Andrew Wilson wrote:
Looks like you're the first plugin writer for the TeamServer :)
The best way to implement your notifier - extend your notification
factory from AbstractNotificationSetFactory, and add it to
build-agent-plugin.xml. AbstractNotificationSetFactory supports
monitoring of notificator configuration file.
Otherwise you can simply implement NotificationSetFactory interface and
add constructor like this:
public MyNotificationSetFactory(NotificationSetFactoryRegistry registry) {
registry.register("aNotificatorCode", this, Arrays.asList(
new UserPropertyInfo("aCode", "ICQ number"),
new UserPropertyInfo("aCode2", "Second ICQ number"),
));
}
You'll be able to get user property using
user.getPropertyValue(new NotificatorPropertyKey("aNotificatorCode",
"aCode"));
Hope this helps,
KIR
--
Kirill Maximov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"
Any more pointers? These hints seem to be out of date. Is there any
JavaDoc for the openapi classes? Any source code to look at?
I'm trying to implement a plugin to work around
http://www.jetbrains.net/jira/browse/TW-764 but maybe you can save me
the effort if you can tell me it won't work!
1) Is there a Notificator.notifyBuildChanged status when a build goes
from "succeeded" to "failed" and vice versa?
2) Is there any way to programmatically disable a build configuration on
build failure?
Thanks,
Robert
PS There seems to be a mismatch between server-openapi.jar and
openapi-1705.jar, when I attach the source jar (openapi-1705.jar) to my
library I get lots of red.
Hello Robert,
Thanks for trying to write a plugin.
Yesterday I've updated a bit plugin development page at
http://www.jetbrains.net/confluence/display/TW/Plugin+Development
Please read, this may help. Please also find my comments below.
Robert Gibson wrote:
All the available javadoc can be found at openapi-1705.jar.
You can write a custom BuildServerListener and register it with SBuildServer.addListener method:
public class MyListener extends BuildServerAdapter {
public MyListener(SBuildServer server) {
server.addListener(this);
}
public void buildChangedStatus(RunningBuild build, Status oldStatus, Status newStatus) {
// Your code here
}
}
You can request the current status of build with build.getStatus() call.
You can also request the status of build configuration with
build.getBuildType().getBuildStatus() call.
((SBuildType)build.getBuildType()).setPaused(true);
That's strange, because this jar is build at the same time when distribution is built.
May be we forgot to add something to the jar. What classes are marked with red?
Kind regards,
KIR
--
Kirill Maximov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"
Kirill Maximov (JetBrains) wrote:
Custom Notifiers
TBD
;)
I'll have a read through. Thanks for your hints.
>>
>> PS There seems to be a mismatch between server-openapi.jar and
>> openapi-1705.jar, when I attach the source jar (openapi-1705.jar) to
>> my library I get lots of red.
E.g. NotificatorAdapter - I get the warning
notifyBuildStarted(RunningBuild, Set]]>) in
'jetbrains.buildServer.notification.NotificationAdapter' clashes with
notifyBuildStarted(RunningBuild, Set) in
'jetbrains.buildServer.notification.Notificator'; both methods have same
erasure, yet neither overrides the other
Note the difference in genericity.
Hello Robert,
In fact, it looks like IDEA's bug. We'll take a look.
This problem shouldn't prevent you from writing a code - looks like
highlighting problem for library classes in IDEA.
Regards,
KIR
--
Kirill Maximov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"
I am trying to write similar plugin. Once the listener has been called how do I trigger a notification message?
Hi Jeff,
I didn't catch you exactly. What kind of plugin do you write? If your listener was called
you should use your transport to deliver notification to your users.
Regards,
KIR
Sorry. I don't understand your response. I have created a BuildServerListener that listens for buildChangedStatus. If the old status was a failure and the new status was successful, I would like to notify users that the build has been fixed ( i.e. send an email, jabber message, etc. Whatever the user has set for his preferences). I just don't know how to send the notification.
I don't know what you mean by "use your transport to deliver notification to your users". Does that mean I have to use my own mechanism? I just want to initiate the same action that would occur normally by TeamCity.
Currently I am trying the following but don't if this will work. Am I on the right track?
Collection notificators = notificatorRegistry.getNotificators();
for (Iterator iterator = notificators.iterator(); iterator.hasNext();)
{
Notificator notificator = (Notificator)iterator.next();
notificator.notifyBuildSuccessful(build, build.getCommitters(SelectPrevBuildPolicy.SINCE_LAST_SUCCESSFULLY_FINISHED_BUILD ).getUsers());
Jeff,
I thought you're writing another notificator for TeamCity.
As you described your use case, it looks you do everything right.
With kind regards,
KIR
--
Kirill Maximov
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"
Thank you for your response.
I have one more question and a comment/bug report.
First the question. Notificators do not have knowledge about a user's notification rules. So currently my code sends a notification for each Notificator. Is there a way to know which Notificators the user wants to be notified by?
Now the comment/bug. The buildChangedStatus() method of the build server listener does not get notified when the build changes from an error state to a successful state.
Thanks,
Jeff