如何通过WIQL C#代码找到TFS中所有Sprint的错误,功能,任务工作?

时间:2018-02-22 07:38:28

标签: c# tfs azure-devops wiql

我想查找查询以查找所有bugs,Task,Feature,Stories 在我的团队的所有冲刺中 我的项目名称中有2个团队" MRI_Scrum_GIt " cantains 2团队 Phoneix和SS ,这两个团队包含那些受尊敬的冲刺(正在进行或已完成)
如何在我的案例SS和phoniex中获得项目中的所有团队(查询)。[/ p>

enter image description here

1 个答案:

答案 0 :(得分:1)

我使用群组操作创建了查询而不是操作" In":

enter image description here

对于我的项目,保存查询中的wiql是:

  

SELECT [System.Id],[System.WorkItemType],[System.Title],[System.AssignedTo],[System.State],[System.Tags] FROM WorkItemLinks WHERE([Source]。[System。 TeamProject] =' VSTSScrum' AND([Source]。[System.WorkItemType] =' Bug' OR [Source]。[System.WorkItemType] =' Product Backlog Item&# 39; OR [Source]。[System.WorkItemType] =' Feature')AND([Source]。[System.IterationPath] UNDER' VSTSScrum \ SS' OR [Source]。[ System.IterationPath] UNDER' VSTSScrum \ Phoneix'))和([System.Links.LinkType] =' System.LinkTypes.Hierarchy-Forward')和([目标]。[系统] .WorkItemType] ='任务' OR [目标]。[System.WorkItemType] ='产品待办事项项目')ORDER BY [System.Id]模式(递归)

您的请求的源代码:

using Microsoft.TeamFoundation.WorkItemTracking.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QueryLinkedWIQL
{
    class Program
    {
        static void Main(string[] args)
        {
            WorkItemStore _wistore = new WorkItemStore("http://server/collection");

            string _teamProject = "VSTSScrum";
            string _teamPhoneixRootIteration = "VSTSScrum\\Phoneix";
            string _teamSSRootIteration = "VSTSScrum\\SS";

                string _wiql = string.Format("SELECT [System.Id] FROM WorkItemLinks WHERE ([Source].[System.TeamProject] = '{0}'"+ 
                "AND ( [Source].[System.WorkItemType] = 'Bug'  OR  [Source].[System.WorkItemType] = 'Product Backlog Item'  OR  [Source].[System.WorkItemType] = 'Feature' ) " + 
                "AND ( [Source].[System.IterationPath] UNDER '{1}'  OR  [Source].[System.IterationPath] UNDER '{2}' )) " + 
                "And ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward') And " + 
                "([Target].[System.WorkItemType] = 'Task'  OR  [Target].[System.WorkItemType] = 'Product Backlog Item') ORDER BY [System.Id] mode(Recursive)",
                _teamProject, _teamPhoneixRootIteration, _teamSSRootIteration);

            Query _query = new Query(_wistore, _wiql);

            WorkItemLinkInfo[] _links = _query.RunLinkQuery();

            foreach(WorkItemLinkInfo _link in _links)
            {
                //process link info item ....
            }
        }
    }
}

==============================

如果您不了解所有团队。你可以在这里找到它们:Add teams and team members

在这种情况下,您的所有团队都必须进行默认迭代" ProjectName \ IterationName"。

using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QueryLinkedWIQL
{
    class Program
    {
        static List<string> ListTeams(TfsTeamProjectCollection pTpc, Project pProject)
        {
            TfsTeamService _teamService = pTpc.GetService<TfsTeamService>();
            var _teams = _teamService.QueryTeams(pProject.Uri.ToString());
            return (from t in _teams select t.Name).ToList();
        }

        static string ConstructTeamsString(string pProjectName, List<string> pTeamNames)
        {
            string _val = "";

            for(int  i = 0; i< pTeamNames.Count; i++)
                if (pTeamNames[i] == "SS" || pTeamNames[i] == "Phoneix") // I have many teams without iteration root name. So I use this if to remove unneeded teams. You can remove this line
                    _val += ((_val != "") ? " OR " : "") + string.Format("[Source].[System.IterationPath] UNDER '{0}\\{1}'", pProjectName, pTeamNames[i]);

            return _val;
        }

        static void Main(string[] args)
        {
            string _teamProject = "VSTSScrum";

            TfsTeamProjectCollection _tpc = new TfsTeamProjectCollection(new Uri("http://server/collection"));

            WorkItemStore _wistore = _tpc.GetService<WorkItemStore>();

            string _teamsStr = ConstructTeamsString(_teamProject, ListTeams(_tpc, _wistore.Projects[_teamProject]));

            string _wiql = string.Format("SELECT [System.Id] FROM WorkItemLinks WHERE ([Source].[System.TeamProject] = '{0}'"+ 
                "AND ( [Source].[System.WorkItemType] = 'Bug'  OR  [Source].[System.WorkItemType] = 'Product Backlog Item'  OR  [Source].[System.WorkItemType] = 'Feature' ) " + 
                "AND ( {1} )) " + 
                "And ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward') And " + 
                "([Target].[System.WorkItemType] = 'Task'  OR  [Target].[System.WorkItemType] = 'Product Backlog Item') ORDER BY [System.Id] mode(Recursive)",
                _teamProject, _teamsStr);

            Query _query = new Query(_wistore, _wiql);

            WorkItemLinkInfo[] _links = _query.RunLinkQuery();

            foreach(WorkItemLinkInfo _link in _links)
            {
                //process link info item ....
            }
        }
    }
}