Month: April 2013

Extra tricks for sending webhooks to HipChat from tcWebHooks

Posted on Updated on

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.

Advertisements