Issue
I'm currently trying to setup a Jenkins pipeline which kicks off a Python script I'm writing. In this Python script, I need to figure out how to use Azure DevOps API calls. For example, the first task I'm trying to do is download an Artifact.
The typical azure-cli command to do this would be:
az artifacts universal download --organization \"https://dev.azure.com/yourorg/\" --feed yourfeed --name your_artifact --version * --path .
Does anyone know how to write out azure-devops api calls in Python?
Solution
According to this ticket. we could invoke the Azure CLI with following way. For example:
from azure.cli.core import get_default_cli
get_default_cli().invoke(['artifacts', 'universal', 'download', '--organization', '\"https://dev.azure.com/yourorg/\"', '--feed', 'yourfeed', '--name', 'your_artifact', '--version', '*', '--path'])
If you get No module named 'azure.cli.command_modules'
error, please install azure-cli
.
To start using the Azure DevOps extension for Azure CLI,please refer to this.
On how to call azure-cli from python script,you can also refer to this sample on github.
Answered By - Hugh Lin
Answer Checked By - Katrina (JavaFixing Volunteer)