8

I am running the following in a CLI task on Azure Devops (inline)

rem Create the Service Plan
call az appservice plan create --resource-group %RESOURCE_GROUP% --name %SERVICE_NAME% --sku B1

Whch works just fine. However, I'm having to scroll to see the whole thing and I have other commands which are even longer. So I'm trying to split it over multiple lines so I can see more clearly what is going on.

Looking at Microsoft Docs it looked like the solution was to put a backslash on the end of each line. So I tried:

I've tried:

rem Create the Service Plan
call az appservice plan create \
--resource-group %RESOURCE_GROUP% \
--name %APP_SERVICE_NAME% \
--sku B1

Which didn't work. I then read something that recommended the back-tick/back-quote at the end of each line:

rem Create the Service Plan
call az appservice plan create `
--resource-group %RESOURCE_GROUP% `
--name %APP_SERVICE_NAME% `
--sku B1

This also didn't work. Any help greatly appreciated.

Jon Ryan
  • 1,497
  • 1
  • 13
  • 29

4 Answers4

12

The character that you need to use to specify that the command is split over multiple lines, depends on the environment in where the CLI command is run. In other words, it depends on the scriptType property of the AzureCLI@2 command.

  • Powershell/Powershell Core: use a backtick `
  • bash: use backslash \
  • batch: use accent circonflexe ^
Frederik Gheysels
  • 56,135
  • 11
  • 101
  • 154
10

Never mind. Worked it out. Turns out you need to use '^'

rem Create the Service Plan
call az appservice plan create ^
--resource-group %RESOURCE_GROUP% ^
--name %APP_SERVICE_NAME% ^
--sku B1
Jon Ryan
  • 1,497
  • 1
  • 13
  • 29
10

For me the ` character is working. I posted earlier that it wasn't but I was inadvertently using the wrong character.

(That post seems to have been deleted by a moderator though I'm not sure why - perhaps because it was more of a "me too" than an answer, but it did add that the above "^" solution doesn't work for me).

In case it was the same issue as I had, ensure the "Backtick" you use is the correct one (it's immediately to the left of "1" on my microsoft keyboard). I was trying to use a ' in the failed attempt as the CLI docs were reading made it hard to distinguish.

JurorNumber8
  • 101
  • 1
  • 2
0

from azure cloud shell, type AZ, then copy paste the az command with \ for multiple line will not work. but there is a fix, you click on the + sign like a adding a folder sign, it will bring a full page Azure Cloud Shell window, change to Bash from the pull down (default is Poweshell), then you see prompt changed to name@Azure:~$, now you can use az commend with \ for multiple lines.

harry
  • 41
  • 1
  • to clarify my prior post, just to the top left corner in the cloud shell, select bash, then the multiple line command with \ will work – harry May 15 '20 at 21:03
  • [florin](https://stackoverflow.com/users/15341506) posted an [Answer](https://stackoverflow.com/a/66503568) saying "harry's answer is actually the better one; you need to change to a bash shell instead of PS" – Scratte Mar 07 '21 at 10:21