Search IterationID in TFS

We connect Iterations within TFS with an external system to track projects across the company. We used to get involved with using IterationPath in a TFS project, but the problem is that people rename these IterationPaths as project progress, and the connection is lost. So after some research, I'm going to link using IterationID. The IterationID in TFSWarehouse does not match the IterationID in the WorkItemTracking table, and I cannot find an easy way to find the IterationID IterationPath? Has anyone understood how we can achieve this?

+5
source share
4 answers

OK - after some further digging, I found the code below, which repeats through all iterations, so using a subset of this, I get what I need :)

using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

namespace TFSIterationList
{
    class Program
    {
        static void Main(string[] args)
        {
            string tfsServer = "tfs";
            string tfsProject = "Project Name";
            TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(tfsServer);
            WorkItemStore store = new WorkItemStore(tfsServer);
            PrintTreeNodeCount(store, tfsProject);
        }


        private static void PrintTreeNodeCount(WorkItemStore store, string tfsProject)
        {
            int iterationNodeCount = 0;
            NodeCollection rootNodeCollection = store.Projects[tfsProject].IterationRootNodes;
            GetChildNodeCount(rootNodeCollection, ref iterationNodeCount);
            Console.WriteLine(tfsProject + " Iteration nodes : " + iterationNodeCount);
         }

        private static void GetChildNodeCount(NodeCollection nodeCollection, ref int nodeCount)
        {
            nodeCount += nodeCollection.Count;
            for (int i = 0; i < nodeCollection.Count; i++)
            {

                Console.WriteLine(nodeCollection[i].Id + " : " + nodeCollection[i].Path);
                // Console.WriteLine(nodeCollection[i].Name);

                if (nodeCollection[i].ChildNodes.Count > 0)
                {  
                // Recursively walk through the child nodes
                    GetChildNodeCount(nodeCollection[i].ChildNodes, ref nodeCount);
                }
            }
        }

    }
}
+2
source

I would use the powershell snap-in from the latest TFS Power Tools for this.

> $tfs = Get-TfsServer <name> -all
> $tfs.WIT.Projects | % { $_.IterationRootNodes } | ft -auto id, path

 Id Path                                       
 -- ----                                 
100 Test-ConchangoV2\Release 1\Sprint 1        
 92 Test-ConchangoV2\Release 1\Sprint 2        
 97 Test-ConchangoV2\Release 1\Sprint 3        
 91 Test-ConchangoV2\Release 1\Sprint 4        
 94 Test-ConchangoV2\Release 1\Sprint 5        
 93 Test-ConchangoV2\Release 1\Sprint 6        
 96 Test-ConchangoV2\Release 2\Sprint 1        
 90 Test-ConchangoV2\Release 2\Sprint 2        
 98 Test-ConchangoV2\Release 2\Sprint 3        
 99 Test-ConchangoV2\Release 3\Sprint 1        
 95 Test-ConchangoV2\Release 3\Sprint 2        
 89 Test-ConchangoV2\Release 3\Sprint 3        
0
source

TFS, :

from: NodeCollection rootNodeCollection = store.Projects [tfsProject].IterationRootNodes;

to: NodeCollection rootNodeCollection = store.Projects [tfsProject].AreaRootNodes;

, .

0

This can also be achieved using the work item query language ( WIQL on MSDN ).

With WIQL you can request TFS. I used C #, but I believe that this works with most / all .NET languages.

WorkItemStore workItemStore = (WorkItemStore)projectCollection.GetService(typeof(WorkItemStore));
WorkItemCollection queryResults = workItemStore.Query(
                    "Select [System.IterationID], [System.IterationPath] " +
                    "From WorkItems ORDER BY [System.IterationID]");

You can find the specific iterationID by adding a where clause to the query string:

+ " Where [System.IterationPath] = 'Path'");

The request image can be viewed, iterating through them:

foreach (WorkItem workitem in queryResults)
            {
                Console.WriteLine(workitem.IterationID);
            }
0
source

All Articles