0
votes

I use the Azure CLI task on my Azure classic pipeline (no YAML). The pipeline works appropriately, the only problem is that this task shows an error. I use this inline script for the task:

$containers = $(call az storage container list --connection-string '...') | ConvertFrom-Json -Depth 5
$containers | where{$_.name -like "..."}
$lastContainers = $containers | Select-Object -Last 5
$containers.ForEach({ If ($_ -notin $lastContainers) {call az storage container delete --name $_.name --connection-string '...' } });

I replaced my real connection string with .... I get this error about the last task (Azure CLI) when I run the pipeline (all of the previous steps end successfully):

D:\a\9\s>$containers = $(call az storage container list --connection-string '...') | ConvertFrom-Json -Depth 5 
'$containers' is not recognized as an internal or external command, operable program or batch file.
##[error]Script failed with error: Error: The process 'D:\a\_temp\azureclitaskscript1587632019088.bat' failed with exit code 255

I have a similar YAML pipeline that uses this same script and everything works just fine. I use call in front of Azure commands as suggested on GitHub.

1

1 Answers

0
votes

In AzureCLI@2 you select script type:

Type of script: PowerShell/PowerShell Core/Bat/Shell script. Select bash/pscore script when running on Linux agent or batch/ps/pscore script when running on Windows agent. PowerShell Core script can run on cross-platform agents (Linux, macOS, or Windows)

Additionally there may appear some differences in Linux and Windows (this issue with call statement), but if you select there pscore for instance you should get rid of 'call` statement.

So please provide more info in what system and terminal you run this script to give you more help.

I ran you script without call in powershell and all was fine. Please try run it in that way.