Tagging a TFS Git repository during a release

三世轮回 提交于 2019-12-03 16:26:00

You can add tags by using REST API:

POST https://{instance}/DefaultCollection/_apis/git/repositories/{repository}/refs?api-version={version}

[
  {
    "name": {string},
    "oldObjectId": {string}, (The current commit id the ref is at. 0000000000000000000000000000000000000000 when creating a new ref.)
    "newObjectId": {string}
  }
]

Calling Rest API through PowerShell:

$result = Invoke-RestMethod -Uri $uri -Method Get -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}

More information, you can refer to Calling VSTS APIs with PowerShell (apply to tfs 2017)

I have built a vsts extension that does exactly this: https://marketplace.visualstudio.com/items?itemName=jabbera.git-tag-on-release-task

You can add a command line task in your release definition and use git command git tag -a vx.x $(Build.SourceVersion) -m "xxx" to add a tag, check the screenshot below:

=========================================================================

Update:

In order to avoid specifying the working folder where the git reop checked out, you can publish the $(build.sourcesdirectory) to drop folder in build definition, then in release definition, you can simply select the drop folder directory. Check the screenshots below:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!