![](/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.