Part 4 in a series on integrating VSTS with TeamCity
Wouldn’t it be great if TeamCity and VSTS had full builtin support for each other? Well yes, yes it would! Maybe that will happen soon.
If I knew Java well, I could probably have a go at writing a TeamCity addin that encapsulates most of the what the pull request server does - but the idea of spending a few weeks getting up to speed with Java/TeamCity development doesn’t excite me that much.
TeamCity 2017.2 adds VSTS Git support to the Commit Status Publisher build feature. I haven’t been able to try this out yet (due to some other bugs in 2017.2 preventing me from upgrading), but it is possible this could remove or reduce the requirement for the build completion handler.
VCS post-commit hook
Now you’ve seen how to to use the APIs for TeamCity and VSTS, you might also want to implement another optimisation - adding a VCS post-commit hook. You add an additional service hook in VSTS that notifies TeamCity that there’s a code change so that TeamCity knows it should grab the latest commit(s).
- In VSTS Project Settings, go to the Service Hooks tab
- Click ‘+’ to add a new service hook
- Select Web Hooks
- In Trigger on this type of event, select Code pushed
- Optionally, review the Filters and just check the Repository (and branch) that should trigger the event.
- In the URL, enter something like
https://www.example.com/app/rest/vcs-root-instances/commitHookNotification?locator=vcsRoot:(type:jetbrains.git,count:99999),property:(name:url,value:%2Fbuildname,matchType:contains),count:99999the locator can vary depending on your individual requirements
- Enter the username and password to authenticate with TeamCity
- Set Resource details to send, Messages to send and Detailed messages to send to None
- Click Test to confirm that everything works.
The nice thing about this is that rather than TeamCity blindly polling VSTS, VSTS is telling TeamCity when it has something of interest.