2016-09-16 63 views
0

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

在此先感谢。

+0

您是否尝试过使用TFS REST API? https://www.visualstudio.com/docs/integrate/api/wit/work-items#create-a-work-item – ds19

回答

1

您可以在打字稿使用VSTS Node API实现你想要的功能。你需要的方法是​​。

+0

@BandR这是否工作? –

0

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

但是,使用TFS REST API,就像ds19在中建议的那样,powershell脚本会起作用。您可能不需要创建您的所有者扩展程序。

REST API:Create a work item

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” 

} 

更详细的步骤和信息,你可以参考这个博客Build association with work Items in vNext

+0

感谢您的答复帕特里克,我的扩展已经开发使用typescript。它使用外部服务来检索一些数据,我需要为接收的数据创建工作项目。我发现了下面的例子,但它使用了在客户端运行的VSS SDK。 [示例](https://nocture.dk/2016/01/02/lets-make-a-visual-studio-team-services-extension/) – Bandara