我目前正在开发一个项目,我需要使用TFS Rest API发布git标签。我仅限于使用API版本2.0,它没有关于如何POST标记的文档,但是功能必须在那里,因为响应代码并不表示POST是不可能的。我的请求看起来像这样。
POST {root_url}/DefaultCollection/{project}/_apis/git/repositories/{repository}/refs?api-version=2.0"
{
"name": "refs/tags/test",
"objectId": "{commitId}"
}
我得到的错误如下:
{ " $ id":" 1"," innerException":null," message":"值不能为空。\ r \ n \ nParameter name:refUpdates"," typeName":" System.Argu mentNullException,mscorlib,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089"," typeKey":" ArgumentNullE xception""的errorCode":0," EVENTID":0} 远程服务器返回错误:(400)错误请求。
我不太确定是否可以POST一个标签但是应该给出错误。有谁知道如何使用POST创建标签或知道我在哪里可以找到它的文档?
答案 0 :(得分:1)
注意,您发布的REST API已用于Modify one or more refs,但未添加git标记。
使用您在上面发布的REST API时,我可以重现您的问题(请参阅下面的屏幕截图供您参考)。
因此,要创建标记,您需要使用正确的REST API:create annotated tag with the REST API
POST https://{instance}/DefaultCollection/{project}/_apis/git/repositories/{repository}/annotatedTags?api-version={version}
我可以使用api-version=3.2-preview.1
例如:
POST http://SERVER:8080/tfs/DefaultCollection/feb1793b-4d91-4be4-8373-02216ec5c36b/_apis/git/repositories/ee76df2b-7c31-484e-ad3a-1a21e6b43cfc/annotatedTags?api-version=3.2-preview.1
Content-Type: application/json
{"name":"3344","message":"test1020","taggedObjectId":"ee26491f1919a9afc9181c00a259bf689afced28"}
<强>更新强>
如果您使用的是TFS 2015或更早版本,那么它不受支持,您可以使用git tag
命令来执行此操作。
因此,如果REST API是唯一选项,那么解决方案是您必须升级到TFS 2017或更高版本。