Jon Ryan
Jon Ryan

Reputation: 1637

How to split a CLI command in Azure Devops over multiple lines? (Running on Windows)

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.

Upvotes: 10

Views: 18503

Answers (4)

JurorNumber8
JurorNumber8

Reputation: 111

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 ' instead of ` in the failed attempt as the CLI docs were reading made it hard to distinguish.

Upvotes: 11

Frederik Gheysels
Frederik Gheysels

Reputation: 56944

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 ^

Upvotes: 24

harry
harry

Reputation: 41

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.

Upvotes: 0

Jon Ryan
Jon Ryan

Reputation: 1637

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

Upvotes: 12

Related Questions