When we queue a build in TFS, if it failed, TFSBuild will create a bug workitem. If it successes, TFSBuild will update associated workitems.
1 How TFSBuild gets associated changesetsprivate void AnalyzeChangesets(Item lastItems, Item currentItems);
As we know, When we queue a build in TFS, TFSBuild will Label the source code, if the Build successes, TFS will record the Label in Database as the LastGoodBuildLabel of the current Build Definition.And the next time we queue the same build definition, TFSBuild can get LastGoodBuildLabel and CurrentLabel.
The task GenCheckinNotesUpdateWorkItems will get lastItems in LastGoodBuildLabel and currentItems in CurrentLabel.
A If lastItems[i]’s ItemID matches a item in currentItems, like currentItems[j]
Get all changesets between lastItems[i]’s changesetID and currentItems[j]’s changesetID that include this item.
Notice, not all changeset between them include this item
B If lastItems[i]’s ItemID does not match any item in currentItems and does not exist in Latest version
This means that the Item may be deleted in a changeset.Get all changesets between lastItems[i]’s changesetID and VersionSpec.Latest that include this item.
C If currentItems[i]’s ItemID does not match any item in lastItems
Get all changesets between ChangesetVersionSpec(1) and currentItems[i]’s changesetID that include this item.
2 How TFSBuild get associated WorkItems
Each changesets contains a prroperty WorkItems. In the step1 we can get all associated changesets, and then we can get all WorkItems.
3 How associate a WorkItem to changeset
A In Team Explorer, when you check-in a changeset, you can associate workitems to it.
B in Team Explorer, you can edit a changeset and associate workitems to it.
4 How TFSBuild Update WorkItemsTFSBuild will set item["Microsoft.VSTS.Build.IntegrationBuild"] = this.BuildNumber for all associated workitem which have this field.