<blockquote>
<p>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?</p>
</blockquote>
<p>你说得对。我们可以使用编写一个WIQL查询来获取系统id,然后我们可以根据系统ID查询工作项。下面是用python代码获取所有工作项的演示代码。在</p>
<pre><code>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)
</code></pre>
<p>关于更多的演示代码,您可以参考这个<a href="https://github.com/Microsoft/azure-devops-python-samples/blob/master/src/samples/work_item_tracking.py" rel="nofollow noreferrer">link</a>。在</p>