Provisioners not working getting syntax error

Hi Team,

Getting error when run the below template through Azure build pipeline .

ssmstest.ps1 script available inside the Git repository but path not fetching from$(System.DefaultWorkingDirectory)

##[error]Error happened while initializing task: SyntaxError: Unexpected token a in JSON at position 230.

Could you please check below declared powershell ssmstest script path is correct? Please guide us to resolve this syntax error.

Below is the ARM template we are using :

{
“variables”: {
“client_id”:"{{env client_id}}",
“client_secret”: “{{env client_secret}}”,
“tenant_id”: “{{env tenant_id}}”,
“current_path”: “{{env CURR_PATH}}”,
“subscription_id”: “{{env subscription_id}}”
},
“builders”: [{
“type”: “azure-arm”,
“client_id”: “{{user client_id}}”,
“client_secret”: “{{user client_secret}}”,
“resource_group_name”: “packtestrg”,
“storage_account”: “teststoragepacker”,
“temp_compute_name”:“myimagevm”,
“temp_resource_group_name”:“temprgpacker”,
“subscription_id”: “{{user subscription_id}}”,
“tenant_id”: “{{user tenant_id}}”,
“capture_container_name”: “images”,
“capture_name_prefix”: “packerimagetest”,
“os_type”: “Windows”,
“image_publisher”: “MicrosoftWindowsServer”,
“image_offer”: “WindowsServer”,
“image_sku”: “2019-Datacenter”,

“communicator”: “winrm”,
“winrm_use_ssl”: true,
“winrm_insecure”: true,
“winrm_timeout”: “30m”,
“winrm_username”: “administrator”,

"location": "Central US",
"vm_size": "Standard_DS2_v2"

}],

"provisioners":[
  {
  "type": "powershell",
  "inline": [
    "Import-Module ServerManager",
    "Install-WindowsFeature -Name NET-Framework-Features",
    "Install-WindowsFeature -Name telnet-client"
  ]
  },
{
  "type": "powershell",
  "script": "{{user `current_path`}}\\ssmstest.ps1"
},  
  {
    "type": "powershell",
    "inline": [
    "Add-WindowsFeature Web-Server",
    "& $env:SystemRoot\\System32\\Sysprep\\Sysprep.exe /oobe /generalize /quiet /quit /mode:vm",
    "while($true) { $imageState = Get-ItemProperty HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup\\State | Select ImageState; if($imageState.ImageState -ne 'IMAGE_STATE_GENERALIZE_RESEAL_TO_OOBE') { Write-Output $imageState.ImageState; Start-Sleep -s 10  } else { break } }"
    ]
	}		

]
}

{
  "variables": {
    "client_id":"{{env client_id}}",
    "client_secret": "{{env client_secret}}",
    "tenant_id": "{{env tenant_id}}",
    "current_path": "{{env CURR_PATH}}",
    "subscription_id": "{{env subscription_id}}"
  },
  "builders": [
    {
      "type": "azure-arm",
      "client_id": "{{user client_id}}",
      "client_secret": "{{user client_secret}}",
      "resource_group_name": "packtestrg",
      "storage_account": "teststoragepacker",
      "temp_compute_name":"myimagevm",
      "temp_resource_group_name":"temprgpacker",
      "subscription_id": "{{user subscription_id}}",
      "tenant_id": "{{user tenant_id}}",
      "capture_container_name": "images",
      "capture_name_prefix": "packerimagetest",
      "os_type": "Windows",
      "image_publisher": "MicrosoftWindowsServer",
      "image_offer": "WindowsServer",
      "image_sku": "2019-Datacenter",
      "communicator": "winrm",
      "winrm_use_ssl": true,
      "winrm_insecure": true,
      "winrm_timeout": "30m",
      "winrm_username": "administrator",
      "location": "Central US",
      "vm_size": "Standard_DS2_v2"
    }
  ],
  "provisioners": [
    {
      "type": "powershell",
      "inline": [
        "Import-Module ServerManager",
        "Install-WindowsFeature -Name NET-Framework-Features",
        "Install-WindowsFeature -Name telnet-client"
      ]
    },
    {
      "type": "powershell",
      "script": "{{user `current_path`}}\\ssmstest.ps1"
    },
    {
      "type": "powershell",
        "inline": [
          "Add-WindowsFeature Web-Server",
          "& $env:SystemRoot\\System32\\Sysprep\\Sysprep.exe /oobe /generalize /quiet /quit /mode:vm",
          "while($true) { $imageState = Get-ItemProperty HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup\\State | Select ImageState; if($imageState.ImageState -ne 'IMAGE_STATE_GENERALIZE_RESEAL_TO_OOBE') { Write-Output $imageState.ImageState; Start-Sleep -s 10  } else { break } }"
        ]
  	}
  ]
}

Just formatting for a better overview. :wink:

1 Like

Any buddy help on that please

I’ll do… Just be a little bit more patient. :wink:

thanks :slightly_smiling_face:

Hm, i don’t get it. The path is correct as long as CURR_PATH environment variable is set.

If I added the “current_path”: “{{env CURR_PATH}}”, and “script”: “{{user current_path}}\ssmstest.ps1” inside the template getting and syntax ##[error]Error happened while initializing task: SyntaxError: Unexpected token a in JSON at position 230.

curr_path $(System.DefaultWorkingDirectory) not working. Please let me know any other way to declare the variables and Powershell script path inside the template.

You have defined the enironment variable this way?
$Env:curr_path = "$(System.DefaultWorkingDirectory)"
(https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-7)