简体   繁体   English

Azure DevOps Powershell 获取与构建管道相关的工作项

[英]Azure DevOps Powershell get work item related to build pipeline

I have a build pipeline with a trigger on new branch creation.我有一个带有新分支创建触发器的构建管道。 The trigger works fine with me creating a new branch and linking a workitem task to the new branch.触发器适用于我创建新分支并将工作项任务链接到新分支。

I have tried to run the query through the API to retrieve the workitem associated to the build but it always comes back blank.我试图通过 API 运行查询以检索与构建关联的工作项,但它总是返回空白。 I can retrieve the list of workitems in the project no problem.我可以检索项目中的工作项列表没问题。

The URI I am using is:我使用的 URI 是:

https://dev.azure.com/{instance}/{project}/_apis/build/builds/{build id}/workitems?api-version=6.0 https://dev.azure.com/{instance}/{project}/_apis/build/builds/{build id}/workitems?api-version=6.0

This returns a blank value.这将返回一个空白值。 If I remove the "workitems" then I get a list of all the builds with one of the entries matching the build id.如果我删除“工作项”,那么我会得到所有构建的列表,其中一个条目与构建 ID 匹配。 The PAT I am using has full access to the project (currently testing so have not been specific for the access).我正在使用的 PAT 可以完全访问该项目(目前正在测试,因此尚未具体访问该访问权限)。

This is the last step for me to complete and I can piece the whole puzzle.这是我完成的最后一步,我可以拼凑整个拼图。

UPDATE1: 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. UPDATE1:我现在注意到在管道日志中没有相关的工作项,即使我从工作项中创建了分支。

构建日志截图

UPDATE2: I notice if I do a commit and associated the work item then the build lists the related work item. UPDATE2:我注意到如果我进行提交并关联工作项,那么构建会列出相关的工作项。 Does not appear to work when creating a new branch, only comitting to that new branch创建新分支时似乎不起作用,仅提交到该新分支

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.在工作项中创建新分支时,需要在 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.当您运行 Rest API: Builds - Get Build Work Items Refs时,它将显示相关的工作项。

GET https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}/workitems?api-version=6.0

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Powershell 从 azure devops build pipeline 获取组件治理结果 - Powershell to fetch the Component Governance result from azure devops build pipeline 将管道变量作为参数传递到 Powershell 构建步骤在 Azure DevOps 中不起作用 - passing pipeline variable as argument into Powershell build step not working in Azure DevOps Azure DevOps:如何从 Release Pipeline 中的 PowerShell 脚本构建 Azure Pipeline 检索构建工件? - Azure DevOps: How to retrieve a build artifact from build Azure Pipeline from a PowerShell Script in Release Pipeline? Azure devOps管道中的Powershell脚本 - Powershell script in azure devOps pipeline 如何将 Powershell 脚本文件路径从 azure devops repo 传递到 Azure devops 构建管道 - how to pass Powershell script filepath from azure devops repo into Azure devops build pipeline 在 Azure DevOps Powershell 管道任务中获取自己的服务主体名称 - Get own Service Principal Name in an Azure DevOps Powershell pipeline task Azure Devops 管道构建参数 - Azure Devops Pipeline Build Parameters 在 Azure DevOps 管道中运行 Azure powershell 命令 - Run Azure powershell commands in Azure devops pipeline Powershell触发Azure DevOps中的构建 - Powershell to trigger a build in Azure DevOps Azure CLI DevOps 使用 PowerShell 获取已创建项目的 ID - Azure CLI DevOps get ID of created item with PowerShell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM