Categories
Azure

Fix: Azure CLI 2.74.0 pkg_resources Error

Recently I saw intermittent failures of a Python script. However, in my Azure DevOps pipeline, I don’t really knowingly use Python. After today, it just kept consistently failing, which led me to research this issue with the Azure CLI.

/opt/az/lib/python3.12/site-packages/azure/multiapi/storagev2/fileshare/__init__.py:1: UserWarning: 
pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. 
The pkg_resources package is slated for removal as early as 2025-11-30. 
Refrain from using this package or pin to Setuptools<81.

I ran into this issue, and after not too long searching, I could already find an open case on GitHub. The root cause of the issue seems to be the latest Azure CLI 2.74.0, which is no longer working as intended.

Workaround

I would suspect this issue will be fixed for the next version. So for the time being, I check in my Azure Hosted Agent Pipeline whether I run on 2.74.0 and if yes, I downgrade to 2.73.0, which mitigates the issue.

# Retrieve current version
current_version=$(az --version | grep "azure-cli" | awk '{print $2}')
echo "Azure CLI version: $current_version"

if [[ "$current_version" == "2.74.0" ]]; then
  echo "Workaround active: Downgrading Azure CLI from 2.74.0 to 2.73.0"
  
  # Remove current version
  pip uninstall azure-cli -y
  
  # Install target version
  pip install azure-cli==2.73.0
  
  # Confirm installation
  az --version
else
  echo "Azure CLI is not version 2.74.0 workaround skipped, current version is $current_version"
fi

An alternative fix would be to no longer stop on failure, however I did not choose this route to still notice in case something would be failing. As it’s kind of problematic to handle this warning as an error. If this were switched to a more informal note rather than a breaking information, that would also fix it until the root cause is resolved in Azure CLI.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.