Search code examples
powershellteamcity-9.0

How to setup post-commit hook for teamcity in Git using Powershell script?


I am trying to setup Git post-commit hook for a particular project in Teamcity to trigger the builds if there is a change in BitBucket repository.

I am trying to use the following powershell script:

curl --user username:password -X POST "http://teamcity.org.com/app/rest/vcs-root-instances/commitHookNotification?locator=project:(id:project_id)"

It is giving me the following error:

No VCS roots are found for locator 'project:(id:project_id)' with current user 'teamcityuser' (TeamCityUser) {id=1672}. Check
 locator and permissions using '/app/rest/vcs-root-instances?locator=$help' URL.

Is there any other way to configure post-commit hook in Git for teamcity using powershell script?


Solution

  • Project is not a valid locator ID, so you may need to consider changing the URL that you are curling.

    From the TeamCity Documentation, the acceptable locators are as follows:

    1. type:VCS root type - VCS root instances of the specified version control (e.g. "jetbrains.git", "mercurial", "svn")
    2. vcsRoot:( vcsRootLocator) - VCS root instances corresponding to the VCS root matched by "vcsRootLocator"
    3. buildType:(buildTypeLocator) - VCS root instances attached to the matching build configuration
    4. property:(name:name,value:value,matchType:matching) - VCS root instances with the property of name "name" and value matching condition "matchType" (e.g. equals, contains) by the value "value".

    You may be able to get away with structuring your api request to query for the project ID like so:

    curl --user username:password -X POST "http://teamcity.org.com/app/rest/vcs-root-instances/commitHookNotification?locator=property:(name:project,id:project_id,matchtype:contains)"