How to setup Azure DevOps to send commit notification to teamcity

Posted on February 25th, 2019

Find a simpler teamcity commit hook notification url

I'm using Azure DevOps (formerly VSTS) to store my private repositories, since they offer it for free. I do however not like there build system, so I'm using Teamcity. All my build script is written in Cake Build. So I could probably change ... but since it's working.

Lately I have setup up a few new projects and the commit notification url was really long ... so I also wanted to make it easier it I changed host for the source code.

Before it looked like: https://teamcity.domain.tld/app/rest/vcs-root-instances/commitHookNotification?locator=vcsRoot:(type:jetbrains.git),property:(name:url,value:https%3A%2F%2Fusername.visualstudio.com%2FBoats%2F_git%2F2FBoats,matchType:contains)

Escaped /, contains, type ... alot of information ... why not use the id of the vcsRoot in Teamcity.

I really tried lots of stuff here to use my id: Boats ... using Insomnia REST Client simple to setup BasicAuthentication(which can be used to authentication to teamcity) and query the rest api.

https://teamcity.domain.tld/app/rest/vcs-root-instances/commitHookNotification?locator=vcsRoot:(type:jetbrains.git),property:(name:id,value:Boats,matchType:equals)

I really had no idea what I was doing, why would it not work with my id ... was it the wrong name, maybe not possible ...

So I went to explore the API to see it I could figure out what I was doing wrong.

There were no documentation really usable from there own site: Configuring VCS Post-Commit Hooks for TeamCity. Mostly stuff about how it's normally used ... but nothing about how it can be used. No real information about the VcsRoot Locator either ...

Investigating the api I found: https://teamcity.domain.tld/app/rest/vcs-roots which returned:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<vcs-roots count="6" href="/app/rest/vcs-roots">
   <vcs-root id="Boats" name="https://username.visualstudio.com/Boats/_git/Boats" href="/app/rest/vcs-roots/id:Boats"/>
</vcs-roots>

Here was my Boats id ... but still as id ... which I had tried.

Any normal rest api would then return details on: https://teamcity.domain.tld/app/rest/vcs-roots/Boats which it also did.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<vcs-root id="Boats" name="https://username.visualstudio.com/Boats/_git/Boats" vcsName="jetbrains.git" href="/app/rest/vcs-roots/id:Boats">
<project id="ProjectName_2" name="ProjectName" parentProjectId="_Root" href="/app/rest/projects/id:ProjectName_2" webUrl="http://teamcity.domain.tld/project.html?projectId=ProjectName_2"/>
<properties count="11">
   <property name="agentCleanFilesPolicy" value="ALL_UNTRACKED"/>
   <property name="agentCleanPolicy" value="ON_BRANCH_CHANGE"/>
   <property name="authMethod" value="PASSWORD"/>
   <property name="branch" value="refs/heads/master"/>
   <property name="ignoreKnownHosts" value="true"/>
   <property name="secure:password"/>
   <property name="submoduleCheckout" value="CHECKOUT"/>
   <property name="url" value="https://username.visualstudio.com/Boats/_git/Boats"/>
   <property name="useAlternates" value="true"/>
   <property name="username" value="boats"/>
   <property name="usernameStyle" value="USERID"/>
</properties>
<vcsRootInstances href="/app/rest/vcs-root-instances?locator=vcsRoot:(id:Boats)"/>
</vcs-root>

Notice the <vcsRootInstances href="/app/rest/vcs-root-instances?locator=vcsRoot:(id:Boats)"/> in the data ... HURRA. A locator I can use that is actually simple instead of querying on properties I can now set the "ID" of the vcsRoot and use that. So properties is additional data that can be set for git, svn, etc.

Then my commitHookNotification url becomes https://teamcity.domain.tld/app/rest/vcs-root-instances/commitHookNotification?locator=vcsRoot:(id:Boats) and it actually worked ...

Setup a Azure DevOps Service Hook to send a notification when new code is pushed

  • Login to Azure DevOps and select the project you want to create a service hook on when new code is pushed.

enter image description here

  • Go to Project settings in the bottom left cornor.

enter image description here

  • Click on Service hooks

enter image description here

  • Click the + sign to add a new service hook and select Web Hooksin the list.

enter image description here

  • Under Trigger on this type of event select the Code pushed and select the filters you want. I only want for Boats and branch master.

enter image description here

  • Fill in the commitHookNotification url and a username/password and then click Test to verify that it works. Then done click on Finish

enter image description here

I really love Azure DevOps ... well havent really tried that many others, but they all seem to have the same set of features.