Search code examples
apinotificationsteamcityslack

TeamCity API method to get Slack notification info


Im trying to list my TeamCity builds in my own site with the TeamCity API to create dashboard. One feature I need is to notify the right person. To do so I set in the build setting the right Slack channel as the notification configuration. My question is, is there a way to get this info from the TeamCity API? And if not, is there any way to get this info from other place?

Thanks!

UPD: This is how the Slack notifier is configured:

On this picture we choose the 'Slack' option in menu.

Here in bottom option we set the slack channel for this build


Solution

  • You get get the information about Build features via TeamCity REST API and the features will in turn contain information about configured Slack notifiers.

    Example of a response for a GET request to https://<serverUrl>/app/rest/buildTypes/id:MY_BUILD_CONFIGURATION_ID:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <buildType id="MY_BUILD_CONFIGURATION_ID" name="Build configuration name" projectName="project name" projectId="PROJECT_ID" href="/app/rest/buildTypes/id:MY_BUILD_CONFIGURATION_ID" webUrl="https://<serverUrl>/viewType.html?buildTypeId=MY_BUILD_CONFIGURATION_ID">
        ...
        <features count="1">
            <feature id="BUILD_EXT_63" type="notifications">
                <properties count="11">
                    <property name="branchFilter" value="+:&lt;default&gt;&#xA;+:br_name"/>
                    <property name="buildFinishedFailure" value="true"/>
                    <property name="buildFinishedSuccess" value="true"/>
                    <property name="firstSuccessAfterFailure" value="true"/>
                    <property name="notifier" value="jbSlackNotifier"/>
                    <property name="plugin:notificator:jbSlackNotifier:addBranch" value="true"/>
                    <property name="plugin:notificator:jbSlackNotifier:addBuildStatus" value="true"/>
                    <property name="plugin:notificator:jbSlackNotifier:channel" value="#slack-channel-name"/>
                    <property name="plugin:notificator:jbSlackNotifier:connection" value="PROJECT_EXT_10"/>
                    <property name="plugin:notificator:jbSlackNotifier:maximumNumberOfChanges" value="10"/>
                    <property name="plugin:notificator:jbSlackNotifier:messageFormat" value="verbose"/>
                </properties>
            </feature>
        </features>
        ...
    </buildType>
    

    The property you are interested in is plugin:notificator:jbSlackNotifier:channel