Azure / azure-devtestlab

Azure DevTestLab artifacts, scripts and samples
MIT License
458 stars 602 forks source link

ArgumentException for running azure-devtestlab/Artifacts/windows-run-powershell #814

Closed alphanse82 closed 2 years ago

alphanse82 commented 2 years ago

Hi,

I am using Azure DevTest Labs Create VM (Preview) Task version 3.* ( preview) to create labVM. this works fine. now we wanted to to windows-run-powershell script in VM via artifacts and it failing with with ArgumentException exception.

When I apply artifacts manually in azure portal with same parameter supplied in template , it works fine. but when I ran in azureDevops task , it fails with ArgumentException exception.

Template file :

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json",
    "contentVersion": "1.0.0.0",
    "parameters": {
      "virtualMachineName": {
        "type": "string",
        "defaultValue": "user_alias-ms14"
      },
      "newVMName": {
        "type": "string",
        "defaultValue": "-ms14"
      },
      "labName": {
        "type": "string",
        "defaultValue": "XXX-developer-devbox"
      },
      "size": {
        "type": "string",
        "defaultValue": "Standard_D8s_v3"
      },
      "userName": {
        "type": "string",
        "defaultValue": "vmAdmin"
      },
      "password": {
        "type": "securestring"
      },
      "TagValue": {
      "type": "string",
      "defaultValue": "user_alias"
      },
      "Run_PowerShell_scriptFileUris": {
      "type": "string",
      "defaultValue": ""
      }
    },
    "variables": {
      "labSubnetName": "Subnet-1",
      "labVirtualNetworkId": "[resourceId('Microsoft.DevTestLab/labs/virtualnetworks', parameters('labName'), variables('labVirtualNetworkName'))]",
      "labVirtualNetworkName": "lab_Virtual_Network_Name",
      "vmId": "[resourceId ('Microsoft.DevTestLab/labs/virtualmachines', parameters('labName'), parameters('virtualMachineName'))]",
      "vmName": "[concat(parameters('labName'), '/', parameters('virtualMachineName'))]",
      "Run_PowerShell_scriptToRun" : "script.ps1",
      "Run_PowerShell_scriptArguments" : ""
    },
    "resources": [
      {
        "apiVersion": "2018-10-15-preview",
        "type": "Microsoft.DevTestLab/labs/virtualmachines",
        "name": "[variables('vmName')]",
        "location": "[resourceGroup().location]",
        "tags": {
          "alias": "[parameters('TagValue')]"
        },
        "properties": {
          "labVirtualNetworkId": "[variables('labVirtualNetworkId')]",
          "notes": "Visual Studio 2019 Enterprise (latest release) on Windows 10 Enterprise N (x64)",
          "galleryImageReference": {
            "offer": "visualstudio2019latest",
            "publisher": "microsoftvisualstudio",
            "sku": "vs-2019-ent-latest-win10-n",
            "osType": "Windows",
            "version": "latest"
          },
         "dataDiskParameters": [
            {
              "attachNewDataDiskOptions": {
                "diskName": "[concat(parameters('virtualMachineName'), '-datadisk-01')]",
                "diskSizeGiB": "2048",
                "diskType": "Premium"
              }
            }
          ],
          "size": "[parameters('size')]",
          "userName": "[parameters('userName')]",
          "password": "[parameters('password')]",
          "isAuthenticationWithSshKey": false,
          "artifacts": [
            {
              "artifactId": "[resourceId('Microsoft.DevTestLab/labs/artifactSources/artifacts', parameters('labName'), 'public repo', 'windows-run-powershell')]",
              "parameters": [
                {
                  "name": "scriptFileUris",
                  "value": "[parameters('Run_PowerShell_scriptFileUris')]"
                },
                {
                  "name": "scriptToRun",
                  "value": "[variables('Run_PowerShell_scriptToRun')]"
                },
                {
                  "name": "scriptArguments",
                  "value": "[variables('Run_PowerShell_scriptArguments')]"
                }
              ]
            }
          ],
          "labSubnetName": "[variables('labSubnetName')]",
          "disallowPublicIpAddress": true,
          "storageType": "Standard",
          "allowClaim": false
        }
      }
    ],
    "outputs": {
      "labVMId": {
        "type": "string",
        "value": "[variables('vmId')]"
      }
    }
  }
alphanse82 commented 2 years ago

input is array for it was missing one '[' bracket.