How pass multiple string in variable file

i’m trying to pass multi string variable in variable file (var.json). main file (packer.json) is refereeing the variable file but facing problem that multiline strings are not parsing

var file :-1:

“changes”: "
“USER tdebuild”,
“WORKDIR /home/tdebuild/goldenversions/{{user application}}-{{user version}}”,
“ENV HOME /home/tdebuild”,
“EXPOSE 8080”,
"ENTRYPOINT bash /tmp/ && /bin/bash " ",


parker.json :-1:

“builders”: [

 "changes": [ "" ],
  "commit": true,
  "image": "{{user `source_image_name`}}",
  "privileged": true,
  "exec_user": 0,
  "pull": true,
  "targetname": "{{user `application`}}:{{user `version`}}",
  "type": "podman"


how to fix this

Hi, thanks for reaching out.

the Packer legacy json templates only accept string variables, though we do try to allow for shoving an array into those strings:
Take a look at the docs here: User Variables - Templates | Packer by HashiCorp

I think something like

"changes": "\"USER tdebuild\",\"WORKDIR /home/tdebuild/goldenversions/{{user application}}-{{user version}}\",\"ENV HOME /home/tdebuild\",\"EXPOSE 8080\",\"ENTRYPOINT bash /tmp/ && /bin/bash\""

might work.

That said, I think the better solution is to upgrade your template to use the new hcl format so that you can pass in a true array value instead of that escaped string mess. You can use the packer hcl2_upgrade - Commands | Packer by HashiCorp command to get yourself started down that path. Reach out here with any questions.

1 Like

@SwampDragons thanks for replay . I added as you suggested but string parsed but . while execution got some error .is that relates to parsing? or inside main json file variable calling? help me i m new to packer and json


2021/04/22 08:12:27 machine readable: podman,error string{“Error committing container: exit status 125\nStderr: Error: invalid syntax for --change: “USER tdebuild”,“WORKDIR /home/tdebuild/goldenversions/apache-tomcat-9.0.43”,“ENV HOME /home/tdebuild”,“EXPOSE 8080”,“ENTRYPOINT /bin/bash”\n”}
Stderr: Error: invalid syntax for --change: “USER tdebuild”,“WORKDIR /home/tdebuild/goldenversions/apache-tomcat-9.0.43”,“ENV HOME /home/tdebuild”,“EXPOSE 8080”,“ENTRYPOINT /bin/bash”
==> Builds finished but no artifacts were created.
Build ‘podman’ errored after 11 seconds 963 milliseconds: Error committing container: exit status 125
2021/04/22 08:12:27 [INFO] (telemetry) Finalizing.
Stderr: Error: invalid syntax for --change: “USER tdebuild”,“WORKDIR /home/tdebuild/goldenversions/apache-tomcat-9.0.43”,“ENV HOME /home/tdebuild”,“EXPOSE 8080”,“ENTRYPOINT /bin/bash”

Yeah, it looks like while the template accepted the “changes” in that json format, it wasn’t valid once used in the actual “changes” call. I think the easiest ways to solve that are to either not use a variable for “changes” or to move to HCL2