9

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.

wolszakp
  • 1,109
  • 11
  • 25
  • You can install the concrete cli version or [update it to latest version](https://learn.microsoft.com/en-us/azure/devops/cli/azure-devops-cli-in-yaml?view=azure-devops#for-linux-azure-pipelines-steps-linuxyml). – Joey Cai Mar 23 '20 at 06:02
  • `az cli` is preinstalled and I can't e.g. downgrade. My scripts are written using concrete version of `az cli`. After a while default `az cli` version has bump up and my pipeline stopped working. I want to set up `az cli` version and decide by myself when I am ready to go up. – wolszakp Mar 23 '20 at 15:55
  • Another option for the specific symptom is to add the option --only-show-errors to your az cli commands, this will prevent warnings being written to stderr – Brad Albright Mar 12 '21 at 04:12

4 Answers4

7

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
Tim
  • 50
  • 1
  • 2
  • 18
Amit Baranes
  • 7,398
  • 2
  • 31
  • 53
  • 2
    nice, just FYI this command works if you are using image "ubuntu-18.04", if you are using "ubuntu-20.04", change "bionic" to "focal" – Brad Albright Mar 12 '21 at 04:41
2

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.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • 1
    Thanks @Leo for a hint. I don't want to uncheck `Fail on Standard Error` while the rest of the pipeline doesn't make sens when this step is failing. – wolszakp Mar 23 '20 at 15:51
  • 1
    @wolszakp, Be able to understand your choice. But just like what I have test, it seems we could not set up az cli version at this moment, since we do not have the url for specify version az cli to install. You could submit your request for this feature on our UserVoice site (https://developercommunity.visualstudio.com/content/idea/post.html?space=21 ), which is our main forum for product suggestions. Thank you for helping us build a better Azure DevOps. Or we could set up our private agent. – Leo Liu Mar 24 '20 at 08:07
  • 1
    Thanks @Leo for your support and fast reaction. I really like Azure DeOps. I am also impressed how fast it is developing. Here is suggestion: https://developercommunity.visualstudio.com/idea/960733/set-up-fixed-az-cli-version-in-my-pipeline.html – wolszakp Mar 24 '20 at 09:41
1

Right now it is not supported. I've created suggestion to add this feature: https://developercommunity.visualstudio.com/idea/960733/set-up-fixed-az-cli-version-in-my-pipeline.html

wolszakp
  • 1,109
  • 11
  • 25
0

Please note, to get this solution to work, you need to run

sudo apt-get update

Before

sudo apt install

Otherwise the downloaded lists of versions does not update, and apt install will report it can't find the version.

Tim Genge
  • 11
  • 1