如何使用 Powershell 脚本在 Git 中为 teamcity 设置 post-commit 挂钩?

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

我正在尝试为 Teamcity 中的特定项目设置 Git post-commit 挂钩,以便在 BitBucket 存储库发生更改时触发构建。

我正在尝试使用以下 powershell 脚本:

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

它给我以下错误:

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.

是否有任何其他方法可以使用 powershell 脚本在 Git 中为 teamcity 配置 post-commit 挂钩?

项目不是有效的定位器 ID,因此您可能需要考虑更改您正在卷曲的 URL。

根据 TeamCity 文档,可接受的定位器如下:

  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".

您可以像这样构造您的 api 查询项目 ID 的请求:

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)"