首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用python从Azure上的workItem获取ID

使用python从Azure上的workItem获取ID
EN

Stack Overflow用户
提问于 2021-05-05 20:13:05
回答 1查看 631关注 0票数 0

我想从Azure DevOPS中的多个项目获得特定DevOPS的ID。

我尝试下面的代码

代码语言:javascript
复制
from azure.devops.connection import Connection
from azure.devops.v5_1.work_item_tracking.models import Wiql
from msrest.authentication import BasicAuthentication

 

pat = 'my_PAT'

organization = 'https://dev.azure.com/ORG/PROJ'
 
credentials = BasicAuthentication('', pat)

connection = Connection(base_url=organization, creds=credentials)
wit_client = connection.clients.get_work_item_tracking_client()

tp_query = Wiql(query="""


SELECT [System.Id] FROM workitems WHERE [System.Title] CONTAINS WORDS 'ESA-2525'

""")

 
for plan in wit_client.query_by_wiql(tp_query).work_items:

    print(f"Results for {plan.id}")

我得到的错误是回溯(最近一次调用):

文件"C:\Users\P70252\source\repos\Azure_WIKI_PostUpgrades\Azure_WIKI_PostUpgrades\devops.py",第15行,在

代码语言:javascript
复制
wit_client = connection.clients.get_work_item_tracking_client()

文件"C:\Program (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\azure\devops\released\client_factory.py",line 170,in get_work_item_tracking_client

代码语言:javascript
复制
return self._connection.get_client('azure.devops.released.work_item_tracking.work_item_tracking_client.WorkItemTrackingClient')

文件"C:\Program (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\azure\devops\connection.py",第45行,在get_client中

代码语言:javascript
复制
self._client_cache[client_type] = self._get_client_instance(client_class)

文件"C:\Program (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\azure\devops\connection.py",第58行,在_get_client_instance中

代码语言:javascript
复制
url = self._get_url_for_client_instance(client_class)

文件"C:\Program (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\azure\devops\connection.py",第70行,在_get_url_for_client_instance中

代码语言:javascript
复制
resource_areas = self._get_resource_areas()

文件"C:\Program (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\azure\devops\connection.py",line 120,in _get_resource_areas

代码语言:javascript
复制
self._resource_areas = location_client.get_resource_areas()

文件"C:\Program (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\azure\devops\v5_1\location\location_client.py",line 107,in get_resource_areas

代码语言:javascript
复制
query_parameters=query_parameters)

文件"C:\Program (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\azure\devops\client.py",第77行,在_send中

代码语言:javascript
复制
query_parameters=query_parameters)

文件"C:\Program (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\azure\devops\client.py",第119行,在_create_request_message中

代码语言:javascript
复制
location = self._get_organization_resource_location(location_id)

文件"C:\Program (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\azure\devops\client.py",line 160,in _get_organization_resource_location

代码语言:javascript
复制
return self._get_resource_location(self.normalized_url, location_id)

文件"C:\Program (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\azure\devops\client.py",line 172,in _get_resource_location

代码语言:javascript
复制
Client._locations_cache[url] = self._get_resource_locations(url, all_host_types=False)

文件"C:\Program (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\azure\devops\client.py",line 208,in _get_resource_locations

代码语言:javascript
复制
response = self._send_request(request, headers=headers)

文件"C:\Program (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\azure\devops\client.py",第68行,在_send_request中

代码语言:javascript
复制
self._handle_error(request, response)

文件"C:\Program (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\azure\devops\client.py",line 291,in _handle_error

代码语言:javascript
复制
url=request.url))

azure.devops.exceptions.AzureDevOpsAuthenticationError:请求的资源需要用户身份验证:https://dev.azure.com/ORG/PROJ/_apis

按任意键继续。。。

"ESA-2525“是一个虚拟工作项,我将用变量替换它,这样我就可以从不同的项目获得ID。

连接可以工作,但是wiql不工作。有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-05-06 06:14:37

关于这个问题,请参考以下代码

1.package

代码语言:javascript
复制
azure-devops==6.0.0b4

  1. 创建完全访问个人访问令牌

  1. code

代码语言:javascript
复制
pat = '<token>'

organization = 'https://dev.azure.com/jim0375'

credentials = BasicAuthentication('', pat)

connection = Connection(base_url=organization, creds=credentials)
wit_client = connection.clients.get_work_item_tracking_client()

tp_query = Wiql(
    query="SELECT [System.Id] FROM WorkItems WHERE  [System.Title] CONTAINS WORDS 'test'")


for plan in wit_client.query_by_wiql(tp_query).work_items:

    print(f"Results for {plan.id}")

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67408171

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档