简体   繁体   English

如何获取Azure Devops项目的所有工作项(史诗,功能,问题,任务,测试用例,用户故事等)?

[英]How to get all work items(Epics, Features, Issue, Task, Test Case, User Story, etc) for an Azure Devops project?

I am trying to fetch all the work items(Epics, Features, Issue, Task, Test Case, User Story, etc) and then classify them for a given project using Microsoft's azure devops python api (aka vsts) library. 我正在尝试获取所有工作项(史诗,功能,问题,任务,测试用例,用户案例等),然后使用Microsoft的azure devops python api (aka vsts)库为给定项目对它们进行分类。

In the work_item_tracking I am unable to find any function to get all work item or fetch all work item on the basis of it's type. 在work_item_tracking中,我无法找到任何函数来获取所有工作项或根据其类型获取所有工作项。

Is there already a function for getting all work items that I am unable to find or should I write a WIQL query to fetch the required data? 是否已经具有用于获取我找不到的所有工作项的功能,还是应该编写WIQL查询以获取所需的数据?

Is there already a function for getting all work items that I am unable to find or should I write a WIQL query to fetch the required data? 是否已经具有用于获取我找不到的所有工作项的功能,还是应该编写WIQL查询以获取所需的数据?

You are right. 你是对的。 We could use write a WIQL query to fetch the System Ids, then we could according system.Ids to query the workitems. 我们可以使用编写WIQL查询来获取系统ID,然后可以根据system.Ids查询工作项。 The following is the demo code to fetch all of the workitems with python code. 以下是使用python代码获取所有工作项的演示代码。

from vsts.vss_connection import VssConnection
from msrest.authentication import BasicAuthentication
import json
from vsts.work_item_tracking.v4_1.models.wiql import Wiql

def emit(msg, *args):
print(msg % args)

def print_work_item(work_item):
    emit(
        "{0} {1}: {2}".format(
            work_item.fields["System.WorkItemType"],
            work_item.id,
            work_item.fields["System.Title"],
        )
    )

personal_access_token = 'YourPATToken'
organization_url = 'https://dev.azure.com/YourorgName'
# Create a connection to the org
credentials = BasicAuthentication('', personal_access_token)
connection = VssConnection(base_url=organization_url, creds=credentials)
wiql = Wiql(
        query="""select [System.Id] From WorkItems """
    )

wit_client = connection.get_client('vsts.work_item_tracking.v4_1.work_item_tracking_client.WorkItemTrackingClient')
wiql_results = wit_client.query_by_wiql(wiql).work_items
if wiql_results:
        # WIQL query gives a WorkItemReference with ID only
        # => we get the corresponding WorkItem from id
        work_items = (
            wit_client.get_work_item(int(res.id)) for res in wiql_results
        )
        for work_item in work_items:
            print_work_item(work_item)

For more demo code, you could refer to this link . 有关更多演示代码,您可以参考此链接

I'm using this documentation to do this. 我正在使用此文档来执行此操作。

With Wiql we can do queries to Azure Devops or TFS, I use Postman to work with it. 使用Wiql,我们可以查询Azure Devops或TFS,我使用Postman来处理它。 The first step is use de following url: https://dev.azure.com/ {organization}/{projectId}/_apis/wit/wiql?api-version=5.0 第一步是使用以下网址: https ://dev.azure.com/ {organization} / {projectId} / _ apis / wit / wiql?api-version = 5.0

Okey the following step is create a query by wiql, to this we will need to use json to send the query: Okey的下一步是通过wiql创建查询,为此,我们将需要使用json发送查询:

{
  "query": "Select [System.Id], [System.Title], [System.State], [System.WorkItemType] From WorkItems"
}

If the request it'a 200 Ok you will obtain a json with all Works Items. 如果请求是200 Ok,您将获得一个包含所有Works项目的json。

My result: Result of my query 我的结果: 我的查询结果

First of all, I am not using the python library, but I can tell you which APIs you have to use. 首先,我没有使用python库,但是我可以告诉您必须使用哪些API。

There is an API to retrieve all the work items . 有一个API可以检索所有工作项 This is just an JSON object with all the work item types and properties. 这只是具有所有工作项类型和属性的JSON对象。 Be aware that this is limited to only 200 workitems each request. 请注意,每个请求仅限于200个工作项。 If you want more workitems, you have to write a WIQL query. 如果需要更多工作项,则必须编写WIQL查询。

GET https://dev.azure.com/{organization}/{project}/_apis/wit/workitems?ids={ids}&api-version=5.0-preview.3

Personally I would like to advise you to use WIQL Queries to retrieve data from Azure DevOps. 我个人想建议您使用WIQL查询从Azure DevOps检索数据。 It is very flexible and it could be used in any situation. 它非常灵活,可以在任何情况下使用。

Here you can find more information about WIQL queries 在这里您可以找到有关WIQL查询的更多信息

Here you can find the detailed information about the Azure DevOps Rest API for WIQL Queries 在这里您可以找到有关WIQL查询Azure DevOps Rest API的详细信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM