# How to Configure Teamscale to Use Post-Commit Hooks

By default, Teamscale uses a poll mechanism to regularly check for new revisions on the server. Depending on the polling interval you configured, this can lead to a large delay between the actual commit and the update of the data in Teamscale, or to a very high load on your version control system server (especially with many projects).

One solution to this problem are post-commit hooks, which are supported by many version control systems. For this, configure your Teamscale project with a large polling interval. Polling will still happen from time to time as a fallback if the post-commit hook failed for some reason. Then you have to configure your version control system to call the following URL after each commit:

http://teamscale.company.com/post-commit-hook?user=USERNAME&access-token=TOKEN&repository=REPOSITORY

Here the part http://teamscale.company.com/ is the URL of your teamscale server. The USERNAME is the name of a user that has build permissions, i.e. is in a group with role Build. The TOKEN is the access token for this user, which is accessible via the user administration page. Finally, REPOSITORY is the URL of the repository as configured in Teamscale. For example, if you have a project reading from the Subversion repository http://svn.company.com/project1/trunk/foo , the URL may be http://svn.company.com/project1/trunk/foo or any prefix, such as http://svn.company.com/project1/ or even http://svn.company.com/ . Note that all projects for which the prefix matches will be checked for updates, so a more specific prefix can help to reduce the server load. However, being too specific does not work. If you pass http://svn.company.com/project1/trunk/foo/some/file as repository parameter, the prefix match will fail and no update is triggered.

You can use both GET and POST requests to call the URL.

# Post-Commit Hooks for Subversion

Subversion supports the execution of arbitrary (shell) scripts for various hooks. The hook that should be used is called post-commit. To access the URL you can use the tools wget or curl. See the SVN book for more details on configuration of commit hooks.

# Post-Commit Hooks for Team Foundation Server

In Team Foundation Server users can configure commit hooks with custom alerts and service hooks (TFS 2015+). Both are available via the admin settings for a team project (gear icon in the top loft corner).

For both methods the REPOSITORY parameter of the URL to the Teamscale commit hook service (as described above) is TFS_URL/TEAM_COLLECTION/FOLDER_PATH , e.g.
http://yourcompany.com/tfs/DefaultCollection/$

/MyProject/Dev/Source .

# Post-Commit Hooks for VSTS Service Hooks

Service Hooks are the successor of Alerts and available in Visual Studio Team Services and Team Foundation Server 2015 onwards. They are easier to set-up and provide debug information if a request fails.

Switch to the Service Hooks tab, create a new subscription and select Web Hooks as type of service. Change the trigger type to Code checked in and enter the TFS repository path you want to monitor for changes:

Create a trigger that listens on code changes.

If you are hosting a Git repository via Team Foundation Server you have to select Code pushed as event type and simply select the repository you want to monitor for changes. Optionally you can restrict the event to only be fired if a specific branch is pushed.

After clicking Next you have to enter the URL of the commit hook:

Configure the service hook action.

All other fields can be left empty and it is not required to send any further data to teamscale at all.

The user who creates the subscription needs to have the TFS permission Edit subscriptions and View subscriptions. See https://www.visualstudio.com/en-us/get-started/integrate/integrating-with-service-hooks-vs for further information.

# Post-Commit Hooks using VSTS Alerts

Deprecation

Service Hooks (available since VS Team Services and Team Foundation Server 2015 onwards) are the successor of Alerts and should be used if possible..

Switch to the alerts tab and create a new alert of type A file is checked in under a specified path:

Create a new TFS commit alert.

Then alter the following fields as shown here:

  • Name: Alter the name to something that reminds you this is the commit hook for Teamscale.

  • Send To: The commit hook url.

  • Format: Change to SOAP.

  • Filter Value: Change from $/ to the folder path used in the commit hook, e.g.$/MyProject/Dev/Source .

If you are hosting a Git repository via Team Foundation Server you have to select the alert type Push > A commit is pushed to a specified repository. The Send To and Format fields have to specified in the same way as described above.

Configure the TFS commit alert.

If you receive an error on save saying that the user needs the right Create a SOAP subscription, an administrator has to issue the following command (e.g., from VisualStudio Command Promt):

tfssecurity.exe /a+ EventSubscription $SUBSCRIPTION:CREATE_SOAP_SUBSCRIPTION n:DOMAIN\USERNAME ALLOW
/collection:TFS_URL/TEAM_COLLECTION

Ensure to substitute DOMAIN and USERNAME with the login of the account you want to create the alert for and TFS_URL/TEAM_COLLECTION with the url to your TFS Team Collection.