Home > Software design >  Retrieving changesets form a work item programmatically
Retrieving changesets form a work item programmatically

Time:01-13

I need to try retrieve a list of changesets that are linked to certain work items and display info on them in the program. But I'm having a lot of trouble figuring it out.

I have been searching the internet extensively for 4 days and have come up empty handed. Is doing this even possible?

I have already tried using wiql http client but it seems to only be able to return work item information.

CodePudding user response:

Use enter image description here

CodePudding user response:

You can reference bellow sample to do that programmatically.

C# sample for your reference to retrieve a list of changesets that are linked to a specific work item.

using System;
using Microsoft.VisualStudio.Services.WebApi;
using Microsoft.TeamFoundation.WorkItemTracking.WebApi;
using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models;
using Microsoft.VisualStudio.Services.Common;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Uri accountUri = new Uri("https://dev.azure.com/{organization}");                 
            String personalAccessToken = "PAT-Here";              
            int workItemId = 227;   // ID of a work item

            // Create a connection to the account
            VssConnection connection = new VssConnection(accountUri, new VssBasicCredential(string.Empty, personalAccessToken));

            // Get an instance of the work item tracking client
            WorkItemTrackingHttpClient witClient = connection.GetClient<WorkItemTrackingHttpClient>();

            WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient<WorkItemTrackingHttpClient>();

            WorkItem workitem = workItemTrackingClient.GetWorkItemAsync(workItemId, expand: WorkItemExpand.Relations).Result;

            Console.WriteLine(workitem.Id);

            Console.WriteLine("Relations with changesets associated:");
            foreach (var relation in workitem.Relations)
            {

                if (relation.Rel == "ArtifactLink")
                {
                    Console.WriteLine(relation.Url);
                }
            }
            Console.ReadLine();
        }
    }
}

enter image description here

PowerShell script calling the enter image description here

  • Related