Search code examples
azure-devopsazure-cliazure-pipelines-yaml

How to specify version for AZ CLI in Azure pipelines in Yaml?


I need to use a task of az cli in a cloud agent, but need to use an older version, today the version used by default in windows-2019 image is az cli v.2.37.0, but I need az cli v.2.34.1.

How can I set this version in the task ?


Solution

  • You can install Azure CLI with the bash task.

    # Specify python version
    - task: UsePythonVersion@0
      inputs:
        versionSpec: '3.x'
        architecture: 'x64'
    
    # Update to latest Azure CLI version
    - bash: pip install --pre azure-cli --extra-index-url https://azurecliprod.blob.core.windows.net/edge
      displayName: 'Upgrade Azure CLI'
    

    You can also specify a version for pip install.

    - bash: pip install -Iv azure-cli==2.34.1 --extra-index-url https://azurecliprod.blob.core.windows.net/edge
      displayName: 'Upgrade Azure CLI'