Чтобы программно извлекать информацию из DevOps Azure, я могу использовать API Python DevOps Azure *1002*.Этот SDK предоставляет несколько клиентов для извлечения различных данных из DevOps Azure.Как подсказал ответ @Levi Lu-MSFT, нужные мне данные могут быть получены из клиента сборки.
Я установил SDK в среде conda с этим YAML:
name: DevOpsData
channels:
- conda-forge
dependencies:
- python=3.6
- pip==19.2.3
- nb_conda_kernels==2.2.1
- papermill==1.0.1
- pandas==0.23.4
- scikit-learn==0.20.0
- lightgbm==2.2.1
- pip:
- prompt_toolkit==2.0.9
- azure-cli==2.0.69
- azure-devops
Я вытащил то, что мне было нужно, используя этот скрипт:
# Copyright (C) Microsoft Corporation. All rights reserved.
from azure.devops.connection import Connection
from msrest.authentication import BasicAuthentication
import pprint
import datetime
if __name__ == "__main__":
# Fill in with your personal access token and org URL
personal_access_token = "MY_ACDESS_TOKEN"
organization_url = "https://dev.azure.com/MY_ORGANIZATION"
# 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)
build_client = connection.clients.get_build_client()
# Get the first page of builds
project = "MY_PROJECT_NAME"
get_builds_response = build_client.get_builds(project=project)
index = 0
while get_builds_response is not None:
for build in get_builds_response.value:
duration = build.finish_time - build.start_time
seconds = duration.days*(24*60*60)+duration.seconds
print("[{}]\t{}\t{}\t{}\t{:,} seconds".format(
index, build.build_number, build.source_branch, build.result,
seconds
))
index += 1
if (get_builds_response.continuation_token is not None
and get_builds_response.continuation_token != ""):
# Get the next page of builds
get_builds_response = build_client.get_builds(
continuation_token=get_builds_response.continuation_token)
else:
# All builds have been retrieved
get_builds_response = None