如何使用Python从Azure Devops获取项目



我制作了一个python脚本,从Azure Devops克隆整个数据库存储库来比较文件。这个回购仍然很小,但肯定不会一直这样。

为了解决这个问题,我正试图写一个脚本,只从repo下载一个项目。问题是这个API太复杂了,我很难理解。目前,身份验证和获取repos是一项OK的任务,但获取特定项被证明是比较困难的。我仍然想使用python包装器。

有人能帮我解决这个问题或重定向到一些有用的链接吗?(API用户手册除外)。

谢谢vshandra。把你的建议作为答案来帮助其他社区成员。

Python API包含与Azure DevOps交互的存储库。该API将为Azure CLI的Azure DevOps扩展提供动力。

from azure.devops.connection import Connection
from msrest.authentication import BasicAuthentication
import pprint
# Fill in with your personal access token and org URL
personal_access_token = 'YOURPAT'
organization_url = 'https://dev.azure.com/YOURORG'
# 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()
# Get the first page of projects
get_projects_response = core_client.get_projects()
index = 0
while get_projects_response is not None:
for project in get_projects_response.value:
pprint.pprint("[" + str(index) + "] " + project.name)
index += 1
if get_projects_response.continuation_token is not None and get_projects_response.continuation_token != "":
# Get the next page of projects
get_projects_response = core_client.get_projects(continuation_token=get_projects_response.continuation_token)
else:
# All projects have been retrieved
get_projects_response = None

完整信息请查看Azure DevOps Python API。

在建立连接时也使用个人访问令牌检查访问令牌

最新更新