Azure / azure-cli

Azure Command-Line Interface
MIT License
3.96k stars 2.94k forks source link

do not execute automatic upgrades while running scripts #28467

Open alexander-kastil opened 6 months ago

alexander-kastil commented 6 months ago

Is your feature request related to a problem? Please describe. I have automatic upgrades for azure cli enabled ... up to now it happened 3 times to me that the upgrade started in the middle of a batch of commands which were saved as a script. after the upgrade the script did not resume and I had to run it again, and if there were random parts in the script I had to clean up the whole environment. This always happend while using WSL

Describe the solution you'd like Implement a solution that the cli does not upgrade itself while executing a batch of commands (script)

yonzhan commented 6 months ago

Thank you for opening this issue, we will look into it.

bebound commented 6 months ago

The auto-upgrade happens when the current command exits successfully. It cannot detect if you are executing a series of commands. I'm not certain how the auto-upgrade interrupts your script, but you can easily disable it.

alexander-kastil commented 6 months ago

I have a bunch of Azure CLI Scripts just like this one ... Use VS Code and the Azure CLI Extension and the Run Line in Terminal command, and it happened several times that in the middle of the commands the CLI started upgrading. Certainly it could disable it ...

env=$RANDOM grp=az204-m02-foodpics-$env loc=westeurope acct=foodpics$env container="food" blob_name=shrimp-vindaloo.jpg file_to_upload="./food-pics/shrimp-vindaloo.jpg" destination_file="./downloaded/shrimp-vindaloo.jpg"

az group create -n $grp -l $loc

az storage account create -l $loc -n $acct -g $grp --sku Standard_LRS

key=$(az storage account keys list -n $acct --query "[0].value" -o tsv)

az storage container create -n $container --account-key $key --account-name $acct

az storage blob upload --container-name $container --file $file_to_upload --name $blob_name --account-key $key --account-name $acct

az storage blob list --container-name $container --output table --account-name $acct --account-key $key

az storage blob download --container-name $container --name $blob_name --file $destination_file --output table --account-key $key --account-name $acct

conStr=$(az storage account show-connection-string -n $acct -g $grp --query connectionString -o tsv)

update appsettings.json

sed -i "s//$key/g" ./blob-console/appsettings.json

echo "storage connection string: " $conStr

bebound commented 6 months ago

I can't repro. Auto-upgrade does not change the stdout and exit code. You need to investigate what happens when auto-upgrade is triggered in your machine.

alexander-kastil commented 6 months ago

Maybe I forgot to mention that I am executing agains WSL Ubuntu 20.x… Not as a script but piping it from an opened script using Azure CLI Tools VS Code Ext & run selected lines in terminal …. Happened to me 4 times … Could you provide a command I could execute to collect data if it happens again? I‘m sure it will happen again

bebound commented 6 months ago

Simply downgrade CLI and then run your scrip step by step, then you should be able to repro it locally. Pay attention to the output and the step it fails.