0
votes

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. I can retrieve the list of workitems in the project no problem.

The URI I am using is:

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. The PAT I am using has full access to the project (currently testing so have not been specific for the access).

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.

Screenshot of build log

UPDATE2: I notice if I do a commit and associated the work item then the build lists the related work item. Does not appear to work when creating a new branch, only comitting to that new branch

1
Erm... Do your builds have workitems associated? :)Grzegorz Ochlik
@Grzegorz, that would defeat the object if I wasn't associating but at the same time I do mention "The trigger works fine with me creating a new branch and linking a workitem task to the new branch."Shane
Hi @Shane Is there any update about this ticket? Feel free to let me know if the suggestion could give you some help. Just a remind of this.Kevin Lu-MSFT

1 Answers

0
votes

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.

enter image description here

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

enter image description here