0

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?

Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107
  • Az CLI is not REST API. Behind the scene it uses it but please can you tell us if your intention is to use Az CLI or [Rest API](https://learn.microsoft.com/en-us/rest/api/azure/devops/?view=azure-devops-rest-6.0)? – Krzysztof Madej Aug 22 '20 at 22:06

1 Answers1

0

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.

Hugh Lin
  • 17,829
  • 2
  • 21
  • 25
  • I was heading down this path but I ran into that issue you notated where it states no module named azure. I installed azure-cli and the devops extension previously on my Jenkins host where these scripts are running but still receive this error. Here is my az --version output: azure-cli 2.10.1 command-modules-nspkg 2.0.3 core 2.10.1 nspkg 3.0.4 telemetry 1.0.4 Extensions: azure-devops 0.18.0 – Python_To_Start Aug 24 '20 at 18:53
  • I'm not sure if this affects anything, but I forgot to mention our Jenkins setup runs in a Docker container. – Python_To_Start Aug 24 '20 at 21:27