我想从Azure DevOPS中的多个项目获得特定DevOPS的ID。
我尝试下面的代码
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行,在
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
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中
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中
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中
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
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
query_parameters=query_parameters)文件"C:\Program (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\azure\devops\client.py",第77行,在_send中
query_parameters=query_parameters)文件"C:\Program (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\azure\devops\client.py",第119行,在_create_request_message中
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
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
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
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中
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
url=request.url))azure.devops.exceptions.AzureDevOpsAuthenticationError:请求的资源需要用户身份验证:https://dev.azure.com/ORG/PROJ/_apis
按任意键继续。。。
"ESA-2525“是一个虚拟工作项,我将用变量替换它,这样我就可以从不同的项目获得ID。
连接可以工作,但是wiql不工作。有什么想法吗?
发布于 2021-05-06 06:14:37
关于这个问题,请参考以下代码
1.package
azure-devops==6.0.0b4pat = '<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}")

https://stackoverflow.com/questions/67408171
复制相似问题