我正在使用 azure python api ( https://github.com/microsoft/azure-devops-python-api ),我需要能够根据自定义字段值查询和查找特定工作项。
我能找到的最接近的是函数create_query,但我希望能够运行诸如
queryRsp = wit_5_1_client.run_query(
posted_query='',
project=project.id,
query='Custom.RTCID=282739'
)
我只需要找到我的 azure devops 工作项,其中自定义字段 RTCID 具有特定的唯一值。
我是否需要使用 API 创建查询、运行它、获取结果,然后删除查询?或者有什么方法可以运行这个简单的查询并使用 azure devops api 获取结果?
最佳答案
您的要求可以实现。
例如,在我这边,有两个工作项具有自定义字段“RTCID”:
下面是如何使用python来设计这个功能(在我这边,组织名称和项目名称都名为“BowmanCP”):
#query workitems from azure devops
from azure.devops.connection import Connection
from msrest.authentication import BasicAuthentication
from azure.devops.v5_1.work_item_tracking.models import Wiql
import pprint
# Fill in with your personal access token and org URL
personal_access_token = '<Your Personal Access Token>'
organization_url = 'https://dev.azure.com/BowmanCP'
# Create a connection to the org
credentials = BasicAuthentication('', personal_access_token)
connection = Connection(base_url=organization_url, creds=credentials)
# Get a client (the "core" client provides access to projects, teams, etc)
core_client = connection.clients.get_core_client()
#query workitems, custom field 'RTCID' has a certain specific unique value
work_item_tracking_client = connection.clients.get_work_item_tracking_client()
query = "SELECT [System.Id], [System.WorkItemType], [System.Title], [System.AssignedTo], [System.State], [System.Tags] FROM workitems WHERE [System.TeamProject] = 'BowmanCP' AND [Custom.RTCID] = 'xxx'"
#convert query str to wiql
wiql = Wiql(query=query)
query_results = work_item_tracking_client.query_by_wiql(wiql).work_items
#get the results via title
for item in query_results:
work_item = work_item_tracking_client.get_work_item(item.id)
pprint.pprint(work_item.fields['System.Title'])
成功地让他们站在我这边:
SDK源代码在这里:
您可以引用上面的源代码。
关于python - azure-devops-python-api 查询工作项,其中字段 == 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73819267/