How to set up az cli concrete version in Azure DevOps

Viewed 3734

After last updates of Azure DevOps our pipelines stopped working.
I am using AZURE CLI tasks.
Investigation shows that az cli was updated to 2.2.0, but nothing was changed on our side.

/usr/bin/az --version
azure-cli                          2.2.0

And some az cli operations starts to print warnings.
Warnings by default are redirected in bash to error stream, so I end up with:

Error: The process '/bin/bash' failed because one or more lines were written to the STDERR stream

How to set up concrete version of az cli for my pipelines?
I want pipelines to be stable with Azure DevOps updates.

3 Answers

When working with Azure DevOps Hosted agents, Some software's installed on the machine automatically. The full list can be found here Ubuntu.

One of the Softwares is Azure CLI:Latest. Therefore, in case you want to downgrade you need to install a new version. The repo is removed after the initial installation so you will need to re-add that first:

AZ_REPO=$(lsb_release -cs)
echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $AZ_REPO main" |
 sudo tee /etc/apt/sources.list.d/azure-cli.list

AZ_VERSION=2.2.0
UBUNTU_CODENAME=bionic

sudo apt install -y --allow-downgrades azure-cli=$AZ_VERSION-1~$UBUNTU_CODENAME

How to set up az cli concrete version in Azure DevOps

To resolve the error, please try to run the task again with the option "Fail on Standard Error" unchecked:

enter image description here

Besides, I am afraid there is no such out of box way to set up concrete version of az cli. Neither can I install an old version in an agent that already has the latest version az cli, either through python commands or chocolate packages:

python commands:

pip install --pre azure-cli --extra-index-url https://azurecliprod.blob.core.windows.net/edge

This command line only install the latest version of az cli. Since I do not have the old version url, I could not test if it works with python command to install the old version az ci when there is a latest version already installed.

Then I test it by the chocolatey package:

https://chocolatey.org/packages/azure-cli/2.1.0#individual

choco install azure-cli --version=2.1.0 --force

But, this installation command still fails due to the existence of a latest version package.

Check this thread for some more details.

Alternatively, you could set up private agent to build your project, and install the old version azure-cli by the choco package.

Hope this helps.

Related