【问题标题】:How to use Azure DevOps / VSTS to fetch query results in python如何使用 Azure DevOps / VSTS 在 python 中获取查询结果
【发布时间】:2020-07-18 06:11:32
【问题描述】:

以下是我当前的代码。它成功连接到组织。如何在 Azure 中获取查询结果,就像他们拥有 here 一样?我知道这已经解决了,但没有任何解释,而且他们正在做的事情存在很大差距。

from azure.devops.connection import Connection
from msrest.authentication import BasicAuthentication
from azure.devops.v5_1.work_item_tracking.models import Wiql

personal_access_token = 'xxx'
organization_url = 'zzz'

# Create a connection to the org
credentials = BasicAuthentication('', personal_access_token)
connection = Connection(base_url=organization_url, creds=credentials)

wit_client = connection.clients.get_work_item_tracking_client()

results = wit_client.query_by_id("my query ID here")

附:请不要将我链接到githubdocumentation。几天来我已经广泛研究了这两种方法,但都没有帮助。

编辑:我添加了成功获取查询的结果行。但是,它返回的 WorkItemQueryResult 类并不完全是需要的。我需要一种方法来查看该列和该列的查询结果。

【问题讨论】:

    标签: python azure-devops


    【解决方案1】:

    所以我可能以最低效的方式解决了这个问题,但希望它可以帮助其他人并找到改进它的方法。

    存储在变量“result”中的 WorkItemQueryResult 类的问题是它不允许显示工作项的内容。

    所以目标是能够使用需要 id 字段的 get_work_item 方法,您可以通过 获得(以相当迂回的方式) item.target.id 来自结果的 work_item_relations。下面的代码是加进去的。

    for item in results.work_item_relations:
       id = item.target.id
       work_item = wit_client.get_work_item(id)
       fields = work_item.fields
    

    这会从结果类中的每个工作项中获取 id,然后授予对该工作项字段的访问权限,您可以通过 fields.get("System.Title") 访问这些字段,等等

    【讨论】:

      猜你喜欢
      • 2019-03-19
      • 1970-01-01
      • 1970-01-01
      • 2011-04-10
      • 1970-01-01
      • 2019-10-20
      • 2019-04-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多