![](/img/trans.png)
[英]How to get a list of dashboards through azure-devops-python-api
[英]azure-devops-python-api query for work item where field == string
I'm using the azure python api ( https://github.com/microsoft/azure-devops-python-api ) and I need to be able to query & find a specific work item based on a custom field value.
我能找到的最接近的是 function 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 源代码在这里:
可以参考上面的源码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.