I am trying to update linked work items with build statuses in ADO.
I created a script that gets linked items from RestApi using the build.id and posts needed updates. Script works fine. My problem is that I discovered that some of the builds have 1-2 linked items in them but other builds have all of the changes and work items listed which is a huge problem in this case.
The workflow in the repo is as follows. Devs create new branches from develop branch, commit changes and do PR back into develop attaching the correct ticket to the PR. Pipelines kick in on merge and after all the stages do a PR into main.
-
Could someone explain why some builds show the correct linked items from PR and some show all of the changes as linked items? I don’t believe it is by design.
-
Does anyone have any ideas on how I could get the PR id programmatically from the build itself? If I could get the PR I’d just query the restApi for items linked to PR instead of the build.
-
Any other creative ideas on how to get through this?
- Could someone explain why some builds show the correct linked items from PR and some show all of the changes as linked items?
If your pipeline had enabled Automatically link work items to builds or releases, please note
What work items are included in automatic linking?
When developing your software, you can link work items when you create a branch, commit, or pull request. Or, you can initiate a branch, commit, or pull request from a work item, automatically linking these objects as described in Drive Git development from a work item.
When automatically linking work items to builds, the following computations are made:
- For a first-time build:
- Identify all work items linked to the branch, commits, and pull requests associated with the build.
- For subsequent builds:
- Identify all work items associated with the current commit (C1) being built.
- Identify all work items associated with the commit (C2) of the last successful build of the same source branch.
- Identify all work items associated with the commits between C1 and C2 in the commit tree.
- Does anyone have any ideas on how I could get the PR id programmatically from the build itself?
If a build of your pipeline was triggered by a PR ($(Build.Reason)
was PullRequest
), you could get the PR id referring to the pre-defined variable value of $(System.PullRequest.PullRequestId)
.
1