new tcWebHooks release. Proper support for TeamCity nested projects

Posted on Updated on

The alpha release from last week is now available as the main release.

This release includes the following new features.

  1. Proper support for TeamCity’s nested project structure. You can now choose if a webhook is inherited by child projects.
  2. ExtraParameters can now be templated in a similar way to the htmlStatusMessage field. This has come in handy for FlowDock integration.

Nested Project support

Webhooks can be inherited by subprojects
Webhooks can be inherited by subprojects

Previous versions of the tcWebHooks plugin did not support nested projects at all. A webhook was configured for a project and only builds in that project would fire them. This version adds support for webhooks to be inherited from parent (and higher) projects.

To enable the old behaviour, I also added control of that feature to the UI as “sub-project builds”. By default webhooks are inherited, but that inheritance can be disabled by deselecting the “All Sub-Project Builds” check box.

Extra Parameter templates

Prior to the latest release, additional parameters were static text only. This release adds the ability to template them in the same manner as the buildStatusHtml message Custom Templates detailed in a previous post.

Here is an example of their use for integration with FlowDock.

 <webhook url="https://api.flowdock.com/v1/messages/chat/your-api-key" enabled="true" format="nvpairs">
   <states>
     <state type="buildFixed" enabled="false" />
     <state type="buildStarted" enabled="false" />
     <state type="buildBroken" enabled="false" />
     <state type="buildSuccessful" enabled="true" />
     <state type="buildFinished" enabled="true" />
     <state type="responsibilityChanged" enabled="false" />
     <state type="beforeBuildFinish" enabled="false" />
     <state type="buildFailed" enabled="true" />
     <state type="buildInterrupted" enabled="false" />
   </states>
   <build-types enabled-for-all="false" enabled-for-subprojects="true">
     <build-type id="bt3" />
   </build-types>
   <parameters>
     <param name="content" value="${message}" />
     <param name="external_user_name" value="teamcity" />
     <param name="tags" value="${projectExternalId},${buildExternalTypeId},${buildResult},teamcity" />
   </parameters>
 </webhook>

These parameters will appear as part of the POST payload and have the ${variables} resolved as per the details in the previous post.

Download and feedback

As usual, please download and post any issues you find on the bugs page.

Custom Templates and branches in tcWebHooks

Posted on

New release available

There is a new release of the TeamCity WebHooks plugin (tcWebHooks – 0.9.12.158).

  1. Adds branch details to the top level of the WebHook Payload Content object (fixes missing branch info in the Name/Value Pairs format).
  2. Fixes an incorrect link on the WebHooks tab of a build.

Download it from SourceForge

Feature Branches and tcWebHooks

I’ve spent the last few evenings working through various issues with the branch support I added a few releases ago. Because I don’t use a VCS that TeamCity supports for branch building, I have never had the opportunity to thoroughly test the feature.

With the help of Jeff, we worked through a number of issues with the Name/Value Pairs (nvpairs) format and my handling of the Branch interface that was added in TeamCity 7.0

The main problem was that the Branch object was being added to the WebHookPayloadContent, but as a child object. Therefore, structured payload formats like JSON and XML were serialising out the contents of the child object correctly, but the nvpairs format was not. It appears that most users are using the nvpairs format. Especially those POSTing to the HipChat webservice endpoint.

As a result of these changes, I have added the following items to the payload object and they are serialised out for all payload formats at the top level.

  • branchDisplayName – A friendly name like “master” or “feature01″.
  • branchName – A name used internally by TeamCity. In my testing, it shows as “<default>” for the “master” and “feature01″ for the “feature01″ branch.
  • branchIsDefault – A Boolean (note the uppercase B), that can be null, true or false depending on whether the build has feature branches enabled (null if not), is the master (true) or a branch (false).

These names are gleaned straight from the “Branch” interface in the TeamCity OpenAPI. I note with interest that the actual TeamCity implementation has different names (myBranchName, myDisplayName), so the JSON payload actually looks like this.

  "branchName": "<default>",
  "branchDisplayName": "master",
  "branchIsDefault": true,
  "branch": {
    "@class": "jetbrains.buildServer.serverSide.impl.BranchImpl",
    "myBranchName": "<default>",
    "myDisplayName": "master"
  },

The upshot is that the WebHookPayloadContent bean is what the custom templates use for building up the htmlBuildStatus message. That means that when configuring a custom message, you can only expect to resolve variables from this bean (using the getters). If value is not set for this instance variable, you will get “null” back. If the getter does not exist, you will get “UNDEFINED”.

A gotcha with the Branch object supplied by TeamCity

The Branch object and the new payload variables are completely dependant on TeamCity passing a useful Branch object to the sRunningBuild.
Please be aware that you will only get a sensible set of branch variables if all the following are true:

  1. You are running TeamCity version 7.1 or higher.
  2. The VCS that the build is built from has support for feature branches provided by TeamCity (currently in TC8 this is only GIT and Mecurial).
  3. You have configured feature branch support in your build so that TeamCity is aware that you have more than one branch that could potentially be used for versioning your build. For more information, please see: http://confluence.jetbrains.com/display/TCD7/Working+with+Feature+Branches

If any of these are not correct, you will get null values for the new branch variables supplied by tcWebhooks.

A list of the object variables in the WebHookPayloadContent bean

As of tcWebHooks verion 0.9.12.158, you should expect the following to be available to the buildStatusHtml template engine.

Variable Name Example Value
projectId GitTestBuilds
message Build Git Test Builds :: Git Test Build has finished. This is build number 22, has a status of “success” and was triggered by Net Wolf
buildStatus Tests passed: 2
buildId 76
buildStateDescription finished
extraParameters null
buildInternalTypeId bt9
branchName feature01
comment null
class class webhook.teamcity.payload.content.WebHookPayloadContent
projectExternalId GitTestBuilds
agentHostname localhost
text Git Test Builds :: Git Test Build has finished. Status: success
buildExternalTypeId GitTestBuilds_GitTestBuild
buildResultPrevious success
projectName Git Test Builds
buildTypeId GitTestBuilds_GitTestBuild
rootUrl http://myserver.company.com:8111
triggeredBy Net Wolf
buildResult success
buildRunners [Maven]
agentOs Linux, version 3.2.0-51-generic
agentName Default Agent
buildName Git Test Build
buildFullName Git Test Builds :: Git Test Build
branchDisplayName feature01
buildResultDelta unchanged
buildStatusUrl http://myserver.company.com:8111/viewLog.html?buildTypeId=GitTestBuilds_GitTestBuild&buildId=76
projectInternalId project5
notifyType buildFinished
buildNumber 22
branchIsDefault false

tcWebHooks 0.9 out of alpha

Posted on

The 0.9.9.155 release has been promoted to be the default download

It supports TC8 and TC7 (and probably earlier versions) and is ready for anybody who wants to use it. Please post any feedback below or on the bugs page.

tcWebHooks 0.9 update

Posted on

For those trying out the new 0.9 branch of tcWebHooks, here is a new version that supports editing webhooks applicable to the build you are viewing.

Also a couple of bug fixes.

  • Adding a new webhook was broken when there were no existing webhooks (adding the first webhook for a project).
  • Some Javascript debugging using Firebugs console, which might have errored on browsers that don’t have Firebug installed.
  • Removed some extra debugging from the javascript code.

Please try it out and let me know if you find any more bugs.

Updated tcWebHooks plugin with build specific webhooks

Posted on Updated on

A frequently requested feature for tcWebHooks is to be able to trigger webhook requests from specific builds in a TeamCity project rather than all builds in a project.

tl;dr

  • You can now select which build(s) a webhook triggers on.
  • Completely rewritten UI – might be bugs.
  • Tested on TC7 and TC8.
  • It’s alpha – Download and feedback please.

The whole story

I’m excited to announce an alpha release of the 0.9 branch which supports choosing which builds a webhook triggers on. I’d really like feedback on the usability and any bugs you find.

Editing Webhooks UI completely re-written

There are a few changes in the core webhook triggering logic which are fairly well tested. However, there has been a major re-write of the javascript and backend MVC controllers to support this extra hierarchy of information being sent back to the browser after an update. This includes moving to JSON as the edit response payload and re-writing nearly all the javascript in the edit webhooks page. This is primarily where any bugs could have crept in. I have tested on Firefox and Chrome, but don’t own a non-linux PC, so have no opportunity to test on browsers from proprietary operating systems.

The changes in the UI are visible on the following pages:

The updated WebHooks edit page

The tcWebHooks editing page now shows how many builds are configured for each webhook.

Screenshot of Edit webhooks page.
On the WebHooks editing page, each webhook shows how many builds in this project will trigger.

Updated WebHooks edit dialog

When editing a WebHook, you can choose which builds to run it on by clicking a new tab inside the Edit Webhooks popup dialog. Clicking the build count will open the dialog directly on the Builds tab. Clicking anywhere else on a webhook opens the dialog on the Webhook Config tab.

Screenshot of new Edit Webhooks dialog
The Edit Webhook dialog now has a Builds tab.

Updated WebHooks list on the Project and Build WebHook tabs

The WebHooks tab on Project pages and Build pages list webhooks per build.

I have broken down the webhooks tabs on the builds and projects pages to show webhooks relevant to all builds in a project as well as webhooks tied to specific builds.

Screenshot of Project tab.
The webhooks tab on Project and Build pages show webhooks grouped by build.

NOTE: this is one aspect that has not been completed. Editing the webhooks for a project takes you to the project webhooks page (shown above) and that page is all working. However, clicking “Edit Build Webhooks” is not currently working. I’ll keep working on that, but wanted to get this alpha out for testing while I worked on that page.

Tested on TC 7.1 and TC8

I have run the plugin on both TeamCity 7.1.5 and 8.0.0. They appear to be working fine despite the huge changes in the TeamCity OpenAPI between those versions. TeamCity introduced the ability to change ProjectId and BuildId values. This means there are now getInternal and getExternal (or similar) methods on the SProject and SBuildType interfaces. Compliing against the old API breaks stuff at runtime in TC8 and compiling against the TC8 API throws no such method errors everywhere.

To mitigate this, I’ve written a wrapper around the methods I use which falls back to the old methods if the new ones are not available. I’m hoping I’ve caught them all and from my testing of the plugin it works on both TC7.1 and TC8. Please post a comment below or on the bugs page if you experience any issues.

Please try it and post any feedback

You can download the 0.9.8.155 release from sourceforge. Please post any feedback in the comments of this post or on the tcWebHooks bugs page.

Making tcWebHooks configurable via TeamCity’s REST API : please discuss

Posted on Updated on

The TeamCity REST API looks to be quite popular (I’ve not knowingly used it). I’ve had a request to add REST API support to tcWebHooks. I’ve not written a public webservices API before. Only really web APIs for services that I control both ends of.

Note: This is not a commitment to build it, more a place to put my thoughts on whether it’s worthwhile or not and how it might work.

I see the four basic requirements.

  • List
  • Create
  • Update
  • Delete
  • Is there anything else needed? Perhaps test?

I think there are three ways it could be accomplished.

  1. Write it myself and probably get it wrong.
  2. Write it myself with a lot input from the users. Who is willing to commit to helping me spec it and test it?
  3. Write a Java API and let someone else write the webservice parts.

The stuff I’ve done before was sending and receiving JSON, and only used POST and GET. Do I need to worry about the whole strict PUT, DELETE etc verbs?

What should the request payload look like? XML? JSON? Name Value Pairs?
What should the response payload look like?

Any good examples? I presume basing it on the existing TeamCity REST API would be the path of least surprise for users. I’ve not used it so don’t have a lot of experience on how it works.

tcWebHooks release to support TeamCity 8

Posted on

TeamCity 8 has just been released and the UI in tcWebhooks was not working correctly due to the new Internal/External Project naming changes.

Basically, the page was being redirected by Teamcity whenever you went to the edit webhooks screen. My JSP controller was looking for “projectId=project01″ in the URL so it was never loading the settings into the UI.

Existing settings appeared to be fine, but editing webhooks required hacking the XML files on the server. This new release fixes that, and adds the projectExternalId value to the webhook payload.

Other than that. Webhooks appear to be firing correctly on my test server running TC8. If you find anything different, please post a comment below or on the Bugs page.

NOTE: Due to changes in the TeamCity API, this version will only work on version 8.0 and above of TeamCity.

If you’re keen to try it out, you can download it from here: tcWebHooksPlugin-0.8.29.142.zip