在TFS中查找IterationID

发布于 2024-07-27 14:12:29 字数 289 浏览 3 评论 0原文

我们将 TFS 内的迭代链接到外部系统,以跟踪整个公司的项目。 过去,我们在 TFS 项目中使用 IterationPath 进行链接,但问题是人们会随着项目的进展重命名这些 IterationPath,并且链接会丢失。 因此,经过一些研究,我正在考虑使用 IterationID 进行链接。 TFSWarehouse 中的 IterationID 与 WorkItemTracking 表中的 IterationID 不同,我似乎无法找到一种简单的方法来查找 IterationPath 的 IterationID? 有人知道我们如何才能实现这一目标吗?

we are linking Iterations within TFS to an external system for tracking projects through the entire company. In the past, we were linking using the IterationPath in a TFS Project, but the problem is that people rename these IterationPaths as the projects progress, and the link is lost. So after some research, I'm thinking of doing the linking by using the IterationID. The IterationID in the TFSWarehouse is NOT the same as the IterationID in the WorkItemTracking table, and I can't seem to find an easy way to find the IterationID of an IterationPath? Anyone got any idea how we may be able to achieve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

暮凉 2024-08-03 14:12:29

好的 - 经过进一步挖掘,发现下面的代码迭代了所有迭代,因此使用其中的一个子集,我将得到我需要的东西:)

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);
                }
            }
        }

    }
}

OK - after some further digging, found the code below that iterates thru all the iterations, so using a subset of this, I will get what I needed :)

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);
                }
            }
        }

    }
}
傾旎 2024-08-03 14:12:29

为此,我将使用最新 TFS Power Tools 中的 powershell 管理单元。

> $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        

I'd 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        
嗫嚅 2024-08-03 14:12:29

如果要打印所有 TFS 区域,请更改以下行:

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

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

感谢您的代码,它对我很有帮助。

if you want to print out all TFS Areas then change the following line:

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

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

thanks for the code it was helpfull at my end.

风筝有风,海豚有海 2024-08-03 14:12:29

这也可以通过使用工作项查询语言 (MSDN 上的 WIQL)。

使用WIQL,您可以查询TFS。 我使用了 C#,但我相信这适用于大多数/所有 .NET 语言。

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

您可以通过在查询字符串中添加 where 子句来找到特定的 iterationID:

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

可以通过迭代查询结果来查看它们:

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

This can also be achieved by using Work Item Query Language (WIQL on MSDN).

With WIQL, you can query TFS. I used C#, but I believe 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 could find a specific iterationID by adding a where clause to your query string:

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

The queryResults can be view by iterating through them:

foreach (WorkItem workitem in queryResults)
            {
                Console.WriteLine(workitem.IterationID);
            }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文