Extra tricks for sending webhooks to HipChat from tcWebHooks

16 04 2013

Brian asked in the comments about setting the notify flag and changing the colour of messages sent to HipChat channels from tcWebHooks.

I emailed the wonderfully responsive HipChat support and Garret from HipChat replied that those extra options are already enabled on the TeamCity endpoint. Because of that you can make use of an undocumented feature of tcWebHooks. “ExtraParmameters”

Edit the ${HOME}/.BuildServer/config/ProjectName/plugin-settings.xml file and add the following before the closing tag of your webhook(s).

       <parameters>
        <param name="color" value="red" />
        <param name="notify" value="1" />
      </parameters>

This will set the message to have a red background and play a sound when the message is posted to the channel. Note the bug below though.

I would suggest splitting up your webhook into two seperate webhooks. One as a “success” webhook and one as a “failed” webhook. Then you can then set the correct background colour based on the result of your build.

Here is a full example. Remember to set your HipChat API URL correctly.

<?xml version="1.0" encoding="UTF-8"?>
<settings>
  <webhooks enabled="true">
    <webhook url="https://api.hipchat.com/.........." enabled="true" format="nvpairs">
      <states>
        <state type="buildStarted" enabled="false" />
        <state type="buildSuccessful" enabled="false" />
        <state type="buildFinished" enabled="true" />
        <state type="buildFixed" enabled="false" />
        <state type="buildBroken" enabled="false" />
        <state type="responsibilityChanged" enabled="false" />
        <state type="beforeBuildFinish" enabled="false" />
        <state type="buildInterrupted" enabled="false" />
        <state type="buildFailed" enabled="true" />
      </states>
       <parameters>
        <param name="color" value="red" />
        <param name="notify" value="1" />
      </parameters>
    </webhook>
    <webhook url="https://api.hipchat.com/.........." enabled="true" format="nvpairs">
      <states>
        <state type="buildStarted" enabled="false" />
        <state type="buildSuccessful" enabled="true" />
        <state type="buildFinished" enabled="false" />
        <state type="buildFixed" enabled="false" />
        <state type="buildBroken" enabled="false" />
        <state type="responsibilityChanged" enabled="false" />
        <state type="beforeBuildFinish" enabled="false" />
        <state type="buildInterrupted" enabled="false" />
        <state type="buildFailed" enabled="false" />
      </states>
       <parameters>
        <param name="color" value="green" />
        <param name="notify" value="1" />
      </parameters>
    </webhook>
  </webhooks>
</settings>


Beware of a bug. Editing webhooks in the UI does not properly retain the extra parameters. I’ll fix that in the next release. Until then, you need to add them back in manually.

This is now fixed in the 0.8.27.139 release.





tcWebHooks 0.8 alpha bugfix release

20 05 2012

Here is a new version of the tcWebHooks 0.8 alpha.

Bug fixes:

  • buildResult was not being set for NVPAIRS format because getter and setter were missing
    NVPAIRS uses apache commons BeanUtils.describe to build the payload, and that requires getter and setters.
    The other formats use ThroughtWorks XStream which uses fields
  • Changed field buildRunner to buildRunners for NVPAIRS format. Other formats were using new pluralised field name.
  • Tidied up unused imports and variables. No more yellow triangles in Eclipse.

I’m pretty sure Jason’s comment regading the hipchat message field containing a blank build result was caused by the buildResult field missing in the NVPAIRS format.  Hopefully this will fix that message.
TODO:

  • buildStatusHtml needs to be added for ResponsibleChanged.

Download version 0.8.branch-build-25.134

As usual, please put comments below or on the bugs page.





tcWebHooks alpha release available – Now much better!

18 05 2012

It’s been a long time coming, but I finally got a chance to work on the tcWebHooks plugin for TeamCity.

I have an alpha release on sourceforge for download here:

The main features are:

  • buildStatusDelta information (broken, fixed, success, failure)
  • being able to trigger webhooks based on deltas (on completion).
  • buildStatusHtml field which contains an html status message containing links back to the build
  • buildStatusUrl field which contains a URL back to the build instance in case you want to roll your own links.
  • Now uses the zip file plugin format. If you are upgrading please remember to remove your old folder and jar as they are no longer required.

There are quite a few refactorings under the hood. Please backup your existing config before you upgrade because the XML format has changed and you won’t be able to roll back.

As usual, please put comments below or on the bugs page.

Here is a screen shot of the new tcWebHooks editor dialog.

It’s very very alpha at the moment. Internally it’s very different. As a result of adding these nested settings, I’ve had to change the XML format. So please please backup your config directory (folder) before installing. I have a format converter, which is unit tested, but you never know ;-)
I’ve removed the “buildStatusChanged” event. It was incredibly misleading, as most people thought it was referring to historical events, rather than in build events.

To install.

  • Shutdown teamcity.
  • Remove the tcWebhooks (or whatever you called it) folder inside your .BuildServer/plugins folder
  • Backup your .BuildServer/config folder
  • Drop the new ZIP into .BuildServer/plugins/
  • Startup teamcity.
Please let me know how you get on using the comment below.




tcPrettyEmail TeamCity plugin now supports STARTTLS

17 04 2012

A recent commenter on the blog mentioned that using a gmail address as the sender address from the tcPrettyEmail plugin was not working due to the fact that smtp.gmail.com wants to use TLS.

I had a quick look through the javax.mail API docs and a browse over stackoverflow, and found that enabling STARTTLS support would be relatively simple. I’m using the spring mail wrapper because it’s bundled with TeamCity, and found that you can pass in extra options using a standard JavaProperties object.

So a few extra lines of code to support the extra tag in TeamCity’s main-config.xml file was all that was really needed to enable it.

While I was pushing a new version, I fixed a couple of missing image files that were causing messages to fail for some less common email message types.

The new version is uploaded to the sourceforge download page and the docs updated to include the new field.

The enable starttls, simply add an argument to the smtp tag (nested inside pretty-email) in main-config.xml. You will probably need to add your username and password to the file as well. Here is an example using gmail as the sender:

  <pretty-email>
    <smtp host="smtp.gmail.com" port="587" 
          username="myGmailUsername"
          password="myGmailPassword"
          from-address="myGmailUsername@gmail.com" 
          from-name="Friendly Name" 
          starttls-enabled="true" />
  </pretty-email>

For futher detail, please see the documentation.





tcPrettyEmail update for TeamCity 6.5.x

5 10 2011

A recent comment from Julien pointed out that tcPrettyEmail messages with Test results are not printing corerctly.

It turns out that the TestBean in the TeamCity API was removed, and I was using that to glean the test detail.  In version 0.8.24.121, I’ve worked around that by building my own bean and passing that to the template engine.

WARNING: This release is only compatible with TeamCity 6.5 and later. For Teamcity 6.0 and earlier, please use the earlier versions.

Screenshot: http://tcplugins.sourceforge.net/screenshot/tcPrettyEmail
Download: http://tcplugins.sourceforge.net/files/tcPrettyEmail
Documentation: http://sourceforge.net/apps/trac/tcplugins/wiki/TcPrettyEmail

If you find a bug or have feature request, please post a comment below or on the tcPrettyEmail bugs page.





New tcWebHooks release to support TeamCity 6.5

16 06 2011

A new version (0.7.25.115) of the tcWebHooks plugin is available.

With the recent release of Teamcity 6.5, some assumptions I was making about the prototype javascript functions proved incorrect. I think the newer version is stricter with badly named functions, or perhaps teamcity has changed some of their internal functions on which I was mistakenly relying.

This release fixes those bugs and also fixes a long standing oversight in the lack of checking of the URL and payload formats when submitting the form. Now, when trying to add a webhook with no url or no payload format selected you are prompted before the dialog goes away. Previously, the dialog would just close and no webhook would be added. It ended up being that my jsp was not setting the content type to text/xml, so the javascript error listener was never firing.

As usual, get the latest from sourceforge. If you find a bug please leave a comment below, or on the bugs page.





New tcWebhooks bugfix release available

6 04 2011

A recent comment on my blog pointed out that the buildStatus field in the webhook POST payload was not accurate.

After some investigation, I noticed the the buildStatus does not get updated until after the build has been marked as “finished” by TeamCity. However, the build is not marked as finished until the plugins have run, so all builds were reporting themselves as “running”.

I have added a new field called buildResult, which gleans the result from the sRunningBuild object, rather than relying on the buildStatus returned by TeamCity.

Thanks to Lloyd for helping me work through the issues and testing. I have now uploaded a new 0.7.23.113 jar to sourceforge.

I also spotted that one field in the JSON payload was incorrectly stating that the notification was for buildStarted when in fact it was buildFinished. This has now been corrected.








Follow

Get every new post delivered to your Inbox.