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)
首先,我不使用python库,但是我可以告诉您必须使用哪些api。在
有一个API可以检索所有work items。这只是一个具有所有工作项类型和属性的JSON对象。请注意,每个请求仅限于200个工作项。如果你想要更多的工作项,你必须写一个WIQL查询。在
我个人建议你使用WIQL查询从azuredevops检索数据。它非常灵活,可以在任何情况下使用。在
在这里您可以找到有关WIQL queries的更多信息
在这里您可以找到有关Azure DevOps Rest API for WIQL Queries的详细信息
我用这个documentation来做这个。在
有了Wiql,我们可以查询azuredevops或TFS,我使用Postman来处理它。 第一步是使用以下网址: https://dev.azure.com/{organization}/{projectd}/\u api/wit/wiql?api版本=5.0
好的,下面的步骤是通过wiql创建一个查询,为此我们需要使用json来发送查询:
如果请求是200行,那么您将获得一个包含所有工作项的json。在
我的结果: Result of my query
你说得对。我们可以使用编写一个WIQL查询来获取系统id,然后我们可以根据系统ID查询工作项。下面是用python代码获取所有工作项的演示代码。在
关于更多的演示代码,您可以参考这个link。在
相关问题 更多 >
编程相关推荐