問題描述
Azure DevOps Powershell 獲取與構建管道相關的工作項 (Azure DevOps Powershell get work item related to build pipeline)
我有一個構建管道,其中包含創建新分支的觸發器。觸發器適用於我創建新分支並將工作項任務鏈接到新分支。
我嘗試通過 API 運行查詢以檢索與構建關聯的工作項,但它總是返回空白的。我可以檢索項目中的工作項列表沒有問題。
我使用的URI是:
https://dev.azure.com/{instance}/{project}/_apis/build/builds/{ build id}/workitems?api‑version=6.0
這會返回一個空白值。如果我刪除“工作項”;然後我得到所有構建的列表,其中一個條目與構建 ID 匹配。我正在使用的 PAT 可以完全訪問該項目(目前正在測試,因此尚未具體訪問)。
這是我要完成的最後一步,我可以拼湊整個難題。
這是我要完成的最後一步。
p>UPDATE1:我現在註意到管道日誌中沒有相關的工作項,即使我從工作項中創建了分支。
UPDATE2:我注意到如果我提交並關聯了工作項,那麼構建會列出相關的工作項。
參考解法
方法 1:
Build pipeline adds related work items by reading the work items associated with the checkout commit.
I have now noticed that in the pipeline log there is no related work item even though I create the branch from within the work item.
When you create the new branch in work item, you need to change the build branch in Build Pipeline.
Then the build will use the newly created branch to build pipeline, the work items will relate to the Build.
When you run the Rest API: Builds ‑ Get Build Work Items Refs, it will show the related work item.
GET https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}/workitems?api‑version=6.0
(by Shane、Kevin Lu‑MSFT)