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.
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
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
Related
My question is a continuation to this post:
Close work items automatically on Release to specific environment
This accepted answer will work perfectly, but only if I can make sure that a build shows just the delta since last build as associated WorkItems, instead of all work items from history. Sometimes I see all items in history as associated work items in a build.
Builds are happening for several environments (Dev, QA, UAT, Prod). How do I make sure that when I run a new build, it only has delta since the last build in that same environment so that I am only looking at new changes that are coming in with a new build?
Update:
I think I get what you mean. Please see if my understanding is accurate: your master branch has many PRs and links to many workitems. You create release1 from the master, and then when the branch is run based on release1 for the first time, the API lists the associated workitems of all the commits of the master. The second time, the incremental workitem compared to the first time can be displayed normally. Later, you created release2 from the master. When the branch was run based on release2 for the first time, the API listed the associated workitems of all commits of the master(This is not you want.). The second time, the incremental workitem compared to the first time can be displayed normally. . What you want is to display incremental workitems from the last run of the branch based on release1 the first time the branch is run based on release2?
If so, it's obviously not possible to use this API to achieve the requirements. As I said in the answer, this API fetch increment refers to the increment based on the same branch, it does not apply to different branches.
But you still have a way to get the "increment" you want, check out this API:
https://learn.microsoft.com/en-us/rest/api/azure/devops/build/builds/get-work-items-between-builds?view=azure-devops-rest-6.0
You just need to compare.
Original Answer:
but only if I can make sure that a build shows just the delta since
last build as associated WorkItems, instead of all work items from
history. Sometimes I see all items in history as associated work items
in a build.
Why do you say 'make sure'?
The API should only get the delta workitems(under the same branch).
I think changes should not contain all of the work items linked to all of the previous commits(since it is only 'changes').
Do you mean the behavior on your side is unstable, do you mean sometimes contains delta changes but sometimes contains all of the changes during the branch lifecycle?
If not, then the understood of yours maybe a little false.
If yes, I think you need to report this issue to the Developer Community. Please also provide your problematic build url there in this situation. StackOverflow is an open forum, so it's not suitable for handling stuff with private information.
Builds are happening for several environments (Dev, QA, UAT, Prod).
How do I make sure that when I run a new build, it only has delta
since the last build in that same environment so that I am only
looking at new changes that are coming in with a new build?
I suggest you put each environment in a different branch, then when you run pipeline based on the related branch, the pipeline should only get the delta changes of current branch and the API should only get the delta workitem commits since the last pipeline run of current branch.
I have set up a branch policy for the main branch that requires pull requests and linked workitems.
A build is configured as part of the branch policy.
Once the build for the merge is completed a release pipeline picks up the artifact. The release has "Pull request deployment" activated in the "Pre-deployment conditions"
In the release pipeline I need the information about the linked workitem. Is there a way to get it?
EDIT
At the end I could use the easy way and rely on the branch name that in our team conventions contains the pbi
The answer is still a good one. So I keep the question here
I believe this is possible, though a little awkward. Steps would be as follows:
Get the Build ID associated with the artifact using the Release.Artifacts.{alias}.BuildId variable
Use the Get Build Work Items Refs API to get the list of work items linked to the PR build
I am wondering why my build pipeline for Azure DevOps is getting practically all the changes instead of just the most recent one?
I only made one change to 1 file, that didn't have an associated work item. This is what the change looks like. As you can see I have only changed one file. So why is it detecting all the changes?
I thought maybe it was because I didn't have this option enabled.
But even with that option enabled on a pipeline setup the EXACT same way all the changes are still pulled. Am I missing something subtle here?
There's an option on the pipeline to automatically link work items that are completed in a run.
You can edit the Pipeline and in the settings, tick Automatically link work items included in this run. You can pick * for all branches, or a specific branch.
Not sure what you did for your pipeline. Every time you change the files of repos for pipeline and then re-run the pipeline, it lists the changes for each build for the current project. This depends on how many changes you have made to the repo project since the last pipeline.
The below shows:
Then, click into the latest pipeline, and that is true, it will list all changes compared to the previous pipeline.
Click into it and you could get the detailed every single change.
We would like to link a TFS work item to a Release so we can easily, with one click from the Release, open a TFS item that contains more info about this release. Info like Release Notes etc.
Is it possible? A release has these variables that can be set when the release is created but they won't hold a (clickable link).
We cannot link work items for an existing release for now, there's already a user voice submitted here to suggest the feature, you can go and vote it up or submit a new one to achieve that in future release.
However you can link work items from changeset, try below steps:
Associate the work items to a changeset when you check in the changes
Then enable Automatically link new work in this build under Option in the build pipeline. Thus when a build completes successfully, it will create links to all work items linked to associated changes. See Automatic linking work items to builds for details.
Create a release pipeline and set the build which created in step2 as the artifacts source (For CI/CD).
You can also enable Report deployment status to Work for the stages under Option in the release pipeline (For set the repository as artifacts source ), thus when the stage completes, it will create links to all work items linked to associated changes.
Please note that in the release summary, it compares the current release with the previous release and then displays the newly added work items associated with changesets. So if you create two releases with the same artifacts source, then the second release will not include the work items... You can reference this thread for details: In TFS 2018, how do I get linked work items to show up in a release?
Once the PR is approved I want to automatically advance the state of the linked work item, but I don't want it to be marked as "complete". Instead I'd like the work item state to be "ready for testing" (still in progress).
For now, work item state can only be changed as complete when merging a PR.
And there has an user voice Customize Work Item State after PR is closed which suggests this feature, you can vote and follow up.
The work around for now is changing the linked work item(s) through CI build (after completing the PR). Detail work flow as follow:
Add a CI build to trigger automatically after the target branch has new commit(s). And add a PowerShell task to update the linked work items state by REST API.
When PR is completed, CI build will be triggered automcally. And the linked work items state will be updated.
You can try to use
Add a rule to a work item type
https://learn.microsoft.com/en-us/azure/devops/organizations/settings/work/custom-rules?view=azure-devops
Create service hook and cosume it later using azure function or logic app https://learn.microsoft.com/en-us/azure/devops/service-hooks/overview?view=azure-devops