Concatenate Variable Values to Builder Values

Hello,
Using a json file, what’s the correct way to append a variable value to a builder value? E.g how to I concat the variable imagename to the builder value vmname?:

{
“variables”: {
“imagename”: “Dev”
},

“builders”: [
{
“vm_name”: “win2019” & {{imagename}},
“type”: “hyperv-vmcx”,

The proper way to do this is described at the JSON template user variables page.

If you want a vm_name key to have a value like "win2019 + imagename" it should be something like:

{
  "variables": {
    "imagename": "Dev"
  },
  "builders": [
    {
      "vm_name": "win2019{{ `user imagename` }}",
      “type”: “hyperv-vmcx”
    }
  ]
}

ie the template interpolates

{{ user  `<variable>`}}

into the value that you’re setting.

Thank you, worked perfectly!

1 Like