Multiline script inside the arm template json blueprint artifact's deployment script

Belous, Nikolay 1 Reputation point
2021-05-31T14:01:46.823+00:00

Are the arm template's deployment scripts, that integrated into Azure Blueprint support multiline scripts anyhow?

I mean.... like this

{
      "$schema": "https://schema.management.azure.com/schemas/2019-08-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
  "parameters": {
    "First": {
      "type": "String"
    },
    "Second": {
      "type": "String"
    }
  },
      "resources": [
        {
          "type": "Microsoft.Resources/deploymentScripts",
          "apiVersion": "2020-10-01",
          "name": "demoSample",
          "location": "[resourceGroup().location]",
          "identity": {
            "type": "UserAssigned",
            "userAssignedIdentities": {
              "/subscriptions/xxxxxx/resourceGroups/xxxxxxxxxxx/providers/Microsoft.ManagedIdentity/userAssignedIdentities/xxxxxxxxxxxx": {
              }
            }
          },
          "kind": "AzureCLI",
          "properties": {
            "azCliVersion": "2.9.1",
            "timeout": "PT30M",
            "scriptContent": "
                    Command1
                    Command2
                    Command3
              ",
            "cleanupPreference": "OnSuccess",
            "retentionInterval": "P1D"
          }
        }
      ]
      }

, but not:

{
      "$schema": "https://schema.management.azure.com/schemas/2019-08-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
  "parameters": {
    "First": {
      "type": "String"
    },
    "Second": {
      "type": "String"
    }
  },
      "resources": [
        {
          "type": "Microsoft.Resources/deploymentScripts",
          "apiVersion": "2020-10-01",
          "name": "demoSample",
          "location": "[resourceGroup().location]",
          "identity": {
            "type": "UserAssigned",
            "userAssignedIdentities": {
              "/subscriptions/xxxxxx/resourceGroups/xxxxxxxxxxx/providers/Microsoft.ManagedIdentity/userAssignedIdentities/xxxxxxxxxxxx": {
              }
            }
          },
          "kind": "AzureCLI",
          "properties": {
            "azCliVersion": "2.9.1",
            "timeout": "PT30M",
            "scriptContent": "Command1; Command2; Command3",
            "cleanupPreference": "OnSuccess",
            "retentionInterval": "P1D"
          }
        }
      ]
      }

Or the only way is to shape it as a VERY LONG SINGLE LINE?
I'm literally stuck with the problem. Single line deployment scripts are very useful anyway, but they look horrible! For the classical arm json template + parameters json file + deployment using New-AzResourceGroupDeployment cmdlet, multiline scripts work just fine, BUT for arm json templates inside the blueprint, I couldn't make it working.

Azure Blueprints
Azure Blueprints
An Azure service that provides templates for quick, repeatable creation of fully governed cloud subscriptions.
72 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. tbgangav-MSFT 10,416 Reputation points
    2021-06-01T04:55:52.46+00:00

    Hi @Belous, Nikolay ,

    As mentioned in this official Azure document, currently the Azure portal and Azure DevOps pipeline can't parse a deployment script with multiple lines. You can either chain the PowerShell commands (by using semicolons or \r\n or \n) into one line, or use the primaryScriptUri property with an external script file.

    For illustration, please find below screenshot that's taken from above mentioned official Azure document.

    101233-image.png


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.