0

我需要从 VSTS 扩展中的自定义构建任务创建 VSTS 工作项,Microsoft 是否为此提供了 API 包装器?最好的方法应该是什么?

提前致谢。

4

2 回答 2

2

您可以在 typescript 中使用VSTS Node API来实现您想要的功能。您需要的方法是createWorkItem()

于 2016-09-19T06:24:56.590 回答
0

目前,TFS 中没有此内置功能或构建任务。

但是,就像 ds19 在powershell 脚本中建议的那样使用 TFS REST API 就可以解决问题。您可能不必创建所有者扩展。

REST API:创建工作项

PATCH https://{instance}/DefaultCollection/{project}/_apis/wit/workitems/${workItemTypeName}?api-version={version}

下面是一个示例代码:

Try

{



$WorkItemAssociatedURL = $collectionURL + $project + “/_apis/build/builds/” + $BuildId + “/workitems?api-version=2.0”

$ResponseJSON = Invoke-RestMethod -Uri $WorkItemAssociatedURL -ContentType “application/json” -headers $headers -Method GET



$CountWorkitems = $ResponseJSON.count

$WorkitemUrlArray = $ResponseJSON.value



for($i = 0; $i -lt $CountWorkitems ; $i++)

{

$body =

‘[

{

“op”: “add”,

“path”: “/fields/Microsoft.VSTS.Build.IntegrationBuild”,

“value”:’ + $BuildNumber +’

}

]’



$WorkitemUpdateURL = $WorkitemUrlArray[$i].url + “?api-version=1.0”



Invoke-RestMethod -Uri $WorkitemUpdateURL -Body $body -ContentType “application/json-patch+json” -headers $headers -Method Patch

}

}



Catch

{

Write-Host “No work item associated with this build. Kindly check the changesets”

}

更多详细步骤和信息,您可以参考此博客与 vNext 中的工作项建立关联

于 2016-09-16T08:53:49.550 回答