![](/img/trans.png)
[英]Authentication when Get Azure DevOps Project Work Items using Python
[英]How to get all work items(Epics, Features, Issue, Task, Test Case, User Story, etc) for an Azure Devops project?
我正在尝试获取所有工作项(史诗,功能,问题,任务,测试用例,用户案例等),然后使用Microsoft的azure devops python api (aka vsts)库为给定项目对它们进行分类。
在work_item_tracking中,我无法找到任何函数来获取所有工作项或根据其类型获取所有工作项。
是否已经具有用于获取我找不到的所有工作项的功能,还是应该编写WIQL查询以获取所需的数据?
是否已经具有用于获取我找不到的所有工作项的功能,还是应该编写WIQL查询以获取所需的数据?
你是对的。 我们可以使用编写WIQL查询来获取系统ID,然后可以根据system.Ids查询工作项。 以下是使用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)
有关更多演示代码,您可以参考此链接 。
我正在使用此文档来执行此操作。
使用Wiql,我们可以查询Azure Devops或TFS,我使用Postman来处理它。 第一步是使用以下网址: https ://dev.azure.com/ {organization} / {projectId} / _ apis / wit / wiql?api-version = 5.0
Okey的下一步是通过wiql创建查询,为此,我们将需要使用json发送查询:
{
"query": "Select [System.Id], [System.Title], [System.State], [System.WorkItemType] From WorkItems"
}
如果请求是200 Ok,您将获得一个包含所有Works项目的json。
我的结果: 我的查询结果
首先,我没有使用python库,但是我可以告诉您必须使用哪些API。
有一个API可以检索所有工作项 。 这只是具有所有工作项类型和属性的JSON对象。 请注意,每个请求仅限于200个工作项。 如果需要更多工作项,则必须编写WIQL查询。
GET https://dev.azure.com/{organization}/{project}/_apis/wit/workitems?ids={ids}&api-version=5.0-preview.3
我个人想建议您使用WIQL查询从Azure DevOps检索数据。 它非常灵活,可以在任何情况下使用。
在这里您可以找到有关WIQL查询的更多信息
在这里您可以找到有关WIQL查询的Azure DevOps Rest API的详细信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.