How to pass a script argument with spaces to Azure CLI task

558 Views Asked by At

There is an Azure CLI v2 task in one of my Azure DevOps release pipelines. Its Script Type is set as Shell and Script Location is set as Inline Script. I am trying to pass a script argument with spaces to an environment variable defined within the script. I am very simple version of my Azure CLI script is below:

az container create --resource-group $(resourceGroup) BLA BLA BLA --environment-variables 'DOTNET_ENVIRONMENT'=$1 'ConnectionStrings__MyDatabase'=$2

ANd in the Script Arguments section I provide args like this:

'$(TargetEnvironment)' `$(ConnectionStrings.MyDatabase)`

Single quotes or double quotes, it doesn't matter because the generated ConnectionStrings__MyDatabase variable is truncated till the first space. For example instead of "Server=tcp:dev.database.windows.net,1433;Initial Catalog=Employess;" it is only "Server=tcp:dev.database.windows.net,1433;Initial".

1

There are 1 best solutions below

0
SiddheshDesai On

Make sure you add double inverted commas "" in your environment variable for the Azure CLI task to consider the values with space.

My Azure Release pipeline variables:-

ConnectionStrings.MyDatabase Server=tcp:dev.database.windows.net,1433;Initial Catalog=Employess

TargetEnvironment Development

enter image description here

My AzureCLITask Inline Script:-

Script reference.

az container create -g siliconrg --name myapp123 --image mcr.microsoft.com/azuredocs/aci-helloworld:latest --cpu 1 --memory 1 --environment-variables "TARGET_ENVIRONMENT=$(TargetEnvironment)" "CONNECTION_STRINGS_MYDATABASE=$(ConnectionStrings.MyDatabase)"

enter image description here

Output:-

enter image description here

Portal:-

enter image description here

I tried the same command from this MS Document in Azure Cloud shell with "" commas and it worked, Refer below:-


az container create -g siliconrg --name myapp --image
mcr.microsoft.com/azuredocs/aci-helloworld:latest --cpu 1 --memory 1
--environment-variables "Server=tcp:dev.database.windows.net,1433;Initial Catalog=Employess;"
"key= Value 1"

Output:-

enter image description here

Portal:-

enter image description here