在发布期间标记TFS Git存储库 [英] Tagging a TFS Git repository during a release

查看:88
本文介绍了在发布期间标记TFS Git存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用TFS 2017设置构建/发布环境.

I am setting our build/release environment using TFS 2017.

我将Build设置为在每次提交后自动运行,并且当我们准备发布应用程序的版本时,会手动创建一个Release,然后将其部署到各种环境中.

I set up the Build to run automatically after each commit, and when we are ready to release a version of our application, a Release is manually created, and then deployed to various environments.

我们想在git存储库中标记发行版本,以便轻松知道哪个git版本对应于二进制文件. Build定义中的"Label Source"设置允许在构建时标记git版本,但是由于我们基于每次提交都会生成很多我们不关心的标记(因为它们不会被部署到任何地方,发布).

We would like to tag released versions in our git repository in order to easily know which git revision correspond to a binary. The "Label Source" setting in the Build definition allows to tag a git revision at build time, but since we build on every commit that would generate a lot of tags which we don't care about (as they are not deployed anywhere until a release is made).

如何设置TFS,以便在创建发行版(或可能将其部署到环境)时,在Git存储库中的相应提交上创建标签?

How can TFS be setup so that when a Release is created (or possibly, deployed to an environment), a tag is created on the corresponding commit in our Git repository?

推荐答案

您可以使用REST API添加标签:

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}
  }
]

通过PowerShell调用Rest API:

Calling Rest API through PowerShell:

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

更多信息,您可以参考使用PowerShell调用VSTS API (适用于tfs 2017)

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

这篇关于在发布期间标记TFS Git存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆