2016-09-16 61 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