Azure-pipelines-tasks: Azure CLI Task - Can't run more than 1 command?

Created on 25 Aug 2017  路  6Comments  路  Source: microsoft/azure-pipelines-tasks

Is there some sort of arbitrary limit on Azure CLI task to only run 1 command? Is this a bug or feature?

Below code:
image

az --version ;
az group create --name "$RSGROUP" --location $REGION ;

az vm create -n $VMname --image CentOS -g $RSGROUP --size $VMsize ;

Results in only the first command running (az --version ; in this case):

2017-08-25T17:34:18.4671741Z ##[section]Starting: AZ CLI: Create VM
2017-08-25T17:34:18.4681743Z ==============================================================================
2017-08-25T17:34:18.4681743Z Task         : Azure CLI Preview
2017-08-25T17:34:18.4681743Z Description  : Run a Shell or Batch script with Azure CLI commands against an azure subscription
2017-08-25T17:34:18.4681743Z Version      : 1.0.2
2017-08-25T17:34:18.4681743Z Author       : Microsoft Corporation
2017-08-25T17:34:18.4681743Z Help         : [More Information](http://go.microsoft.com/fwlink/?LinkID=827160)
2017-08-25T17:34:18.4681743Z ==============================================================================
2017-08-25T17:34:18.6961853Z az group create --name "$RSGROUP" --location $REGION ;
2017-08-25T17:34:18.6961853Z 
2017-08-25T17:34:18.6961853Z az vm create -n $VMname --image CentOS -g $RSGROUP --size $VMsize ;
2017-08-25T17:34:18.7021851Z [command]C:\Windows\system32\cmd.exe /D /S /C ""C:\Program Files (x86)\Python36-32\Scripts\az.bat" login --service-principal -u ******** -p ******** --tenant ********"
2017-08-25T17:34:22.4067133Z [
2017-08-25T17:34:22.4067133Z   {
2017-08-25T17:34:22.4067133Z     "cloudName": "AzureCloud",
2017-08-25T17:34:22.4067133Z     "id": "**scrubbed**",
2017-08-25T17:34:22.4067133Z     "isDefault": true,
2017-08-25T17:34:22.4067133Z     "name": "**scrubbed**",
2017-08-25T17:34:22.4067133Z     "state": "Enabled",
2017-08-25T17:34:22.4067133Z     "tenantId": "********",
2017-08-25T17:34:22.4067133Z     "user": {
2017-08-25T17:34:22.4067133Z       "name": "********",
2017-08-25T17:34:22.4067133Z       "type": "servicePrincipal"
2017-08-25T17:34:22.4067133Z     }
2017-08-25T17:34:22.4067133Z   }
2017-08-25T17:34:22.4077135Z ]
2017-08-25T17:34:22.4077135Z [command]C:\Windows\system32\cmd.exe /D /S /C ""C:\Program Files (x86)\Python36-32\Scripts\az.bat" account set --subscription "**scrubbed**""
2017-08-25T17:34:24.7374767Z [command]C:\Windows\system32\cmd.exe /D /S /C "d:\a\_temp\azureclitaskscript1503682458696.bat"
2017-08-25T17:34:24.7434772Z 
2017-08-25T17:34:24.7434772Z d:\a\r1\a>az --version ; 
2017-08-25T17:34:25.3215529Z azure-cli (2.0.14)
2017-08-25T17:34:25.3215529Z 
2017-08-25T17:34:25.3225062Z acr (2.0.10)
2017-08-25T17:34:25.3225062Z acs (2.0.13)
2017-08-25T17:34:25.3225062Z appservice (0.1.13)
2017-08-25T17:34:25.3225062Z batch (3.1.1)
2017-08-25T17:34:25.3225062Z billing (0.1.3)
2017-08-25T17:34:25.3225062Z cdn (0.0.6)
2017-08-25T17:34:25.3225062Z cloud (2.0.7)
2017-08-25T17:34:25.3225062Z cognitiveservices (0.1.6)
2017-08-25T17:34:25.3225062Z command-modules-nspkg (2.0.1)
2017-08-25T17:34:25.3225062Z component (2.0.7)
2017-08-25T17:34:25.3225062Z configure (2.0.10)
2017-08-25T17:34:25.3225062Z consumption (0.1.3)
2017-08-25T17:34:25.3225062Z container (0.1.8)
2017-08-25T17:34:25.3225062Z core (2.0.13)
2017-08-25T17:34:25.3225062Z cosmosdb (0.1.11)
2017-08-25T17:34:25.3225062Z dla (0.0.10)
2017-08-25T17:34:25.3225062Z dls (0.0.12)
2017-08-25T17:34:25.3225062Z eventgrid (0.1.2)
2017-08-25T17:34:25.3225062Z feedback (2.0.6)
2017-08-25T17:34:25.3225062Z find (0.2.6)
2017-08-25T17:34:25.3225062Z interactive (0.3.7)
2017-08-25T17:34:25.3225062Z iot (0.1.10)
2017-08-25T17:34:25.3225062Z keyvault (2.0.8)
2017-08-25T17:34:25.3225062Z lab (0.0.9)
2017-08-25T17:34:25.3225062Z monitor (0.0.8)
2017-08-25T17:34:25.3225062Z network (2.0.12)
2017-08-25T17:34:25.3225062Z nspkg (3.0.1)
2017-08-25T17:34:25.3225062Z profile (2.0.10)
2017-08-25T17:34:25.3225062Z rdbms (0.0.5)
2017-08-25T17:34:25.3225062Z redis (0.2.7)
2017-08-25T17:34:25.3225062Z resource (2.0.12)
2017-08-25T17:34:25.3225062Z role (2.0.10)
2017-08-25T17:34:25.3225062Z sf (1.0.6)
2017-08-25T17:34:25.3235057Z sql (2.0.9)
2017-08-25T17:34:25.3235057Z storage (2.0.12)
2017-08-25T17:34:25.3235057Z vm (2.0.12)
2017-08-25T17:34:25.3235057Z 
2017-08-25T17:34:25.3235057Z Python (Windows) 3.6.2 (v3.6.2:5fd33b5, Jul  8 2017, 04:57:36) [MSC v.1900 64 bit (AMD64)]
2017-08-25T17:34:25.3235057Z 
2017-08-25T17:34:25.3235057Z Python location 'C:\Program Files\Python36\python.exe'
2017-08-25T17:34:25.3235057Z 
2017-08-25T17:34:26.7287247Z [command]C:\Windows\system32\cmd.exe /D /S /C ""C:\Program Files (x86)\Python36-32\Scripts\az.bat" account clear"
2017-08-25T17:34:28.7336033Z ##[section]Finishing: AZ CLI: Create VM

edit:
Adding batch and command + escape character allows "multiple commands" but what really is one liner.
ie. this below works:

az group create --name %RSGROUP% --location %REGION% &^
az vm create -n %VMNAME% --image CentOS -g %RSGROUP% --size %VMSIZE% --generate-ssh-keys
Release

Most helpful comment

Since you're running it on a windows agent; you need to add call in front of each command to execute all of them.

You should replace your current inline script with this;

 call az --version ; 
 call az group create --name "$RSGROUP" --location $REGION ;
 call az vm create -n $VMname --image CentOS -g $RSGROUP --size $VMsize ;

If you were running it in a Linux environment, the call should be removed.
This is how batch scripts run multiple commands otherwise it would be treated as a oneliner.

All 6 comments

Since you're running it on a windows agent; you need to add call in front of each command to execute all of them.

You should replace your current inline script with this;

 call az --version ; 
 call az group create --name "$RSGROUP" --location $REGION ;
 call az vm create -n $VMname --image CentOS -g $RSGROUP --size $VMsize ;

If you were running it in a Linux environment, the call should be removed.
This is how batch scripts run multiple commands otherwise it would be treated as a oneliner.

You don't need semicolon at the end of the commands like:

call az --version
call az group create --name "$RSGROUP" --location $REGION
call az vm create -n $VMname --image CentOS -g $RSGROUP --size $VMsize 

Why cannot we not just create a script file with azcli with out the call statement - very clunky to add call to every statement !?!?!?!

Why cannot we not just create a script file with azcli with out the call statement - very clunky to add call to every statement !?!?!?!

Because:

This is how batch scripts run multiple commands otherwise it would be treated as a oneliner.

Windows shouldn't use batch for processing AZ-CLI templates in my opinion but thats way it currently is. Alternative is to use Linux agent.

Am not referring to templatesor 'batch', but a series of azcli commands in a file i.e. myscript.bat.
I get that we should define/script network resources via template json files, but an azcli script file itself would be good. for Windows.

We have plans to support modern shells for the Az CLI step. Please track the updates here #5125

Was this page helpful?
0 / 5 - 0 ratings