简体   繁体   中英

How to get items from Azure Devops using Python

I made a python script that clone an entire database repository from Azure Devops to compare files. The repo is still small but it is definitly not staying that way.

To solve this issue, I am trying to write a script that only download an item from the repo. The thing is that the API is quite a mouthful and I have trouble getting into it. For now, authentification and getting repos is an OK task but getting a specific item proved to be harder. I still want to use the python wrapper.

Can someone help me with this issue or redirecting me to some useful links? (except the API user manual).

Thank you vshandra . Posting your suggestions as an answer to help other community members.

The Python API contains repository for interacting with Azure DevOps. The API's will power the Azure DevOps extension for Azure CLI.

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

For complete information check Azure DevOps Python API .

Also to Use Personal access tokens in establishing the connection check Access tokens .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM