Triggering a webhook for every TeamCity build (aka using the _Root project)

Posted on

I was recently asked in the comments whether it is possible to add a webhook to trigger for all builds in all projects.

The answer is: yes, but you have to add it to the configuration manually.

The _Root project

In recent versions of TeamCity, a hierarchy was introduced for projects. This means there is now a “Root” project, which is referred to internally by TeamCity as “_Root”. All projects are descendants of the Root project.

When I added descendant project support for the tcWebhooks plugin, I deliberately didn’t allow configuration of the Root project, because it would be too easy to inadvertently add a webhook to every build on TeamCity, even if there are builds that are not your part of a team’s projects.

However, that logic is applied in the UI, not at the webhook triggering level. Therefore, if you configure a webhook in the _Root project XML file on the TeamCity server, it will add a webhook for every build on every project.

Configuring

Edit ~/.BuildServer/config/projects/_Root/pluginData/plugin-settings.xml

Mine looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<settings>
 <report-tabs>
  <build-report-tab title="Code Coverage" startPage="coverage.zip!index.html"/>
  <build-report-tab title="JavaDoc" startPage="javadoc.zip!index.html" />
 </report-tabs>
 <webhooks enabled="true">
  <webhook url="http://<webhook_end_point>" enabled="true" format="nvpairs">
   <states>
    <state type="beforeBuildFinish" enabled="false" />
    <state type="buildFixed" enabled="false" />
    <state type="buildFailed" enabled="true" />
    <state type="buildSuccessful" enabled="true" />
    <state type="buildStarted" enabled="false" />
    <state type="buildFinished" enabled="true" />
    <state type="buildBroken" enabled="false" />
    <state type="responsibilityChanged" enabled="false" />
    <state type="buildInterrupted" enabled="false" />
   </states>
   <build-types enabled-for-all="true" enabled-for-subprojects="true" />
  </webhook>
 </webhooks>
</settings>
Advertisements

3 thoughts on “Triggering a webhook for every TeamCity build (aka using the _Root project)

    Yann Simon said:
    June 3, 2015 at 09:47

    It would be great if we can configure it from the http interface as well.
    I’d like to enable / disable this web hook per project and doing it all in XML is painful.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s