Skip to content

Instantly share code, notes, and snippets.

@mefellows
Last active November 14, 2019 19:50
Show Gist options
  • Save mefellows/32e5ca354a6c3255bc16 to your computer and use it in GitHub Desktop.
Save mefellows/32e5ca354a6c3255bc16 to your computer and use it in GitHub Desktop.
Packer Community Valid Exit Codes
{
"builders": [
{
"type": "virtualbox-windows-ovf",
"source_path": "output-basebox-vbox/talentsearch-api-1.0.0.ovf",
"headless": false,
"boot_wait": "1m",
"winrm_username": "vagrant",
"winrm_password": "vagrant",
"winrm_wait_timeout": "5m",
"guest_additions_mode": "disable",
"shutdown_timeout": "2h",
"shutdown_command": "shutdown /s /t 7200 /f /d p:4:1 /c \"Packer Shutdown\"",
"vboxmanage": [
[
"modifyvm",
"{{.Name}}",
"--memory",
"2048"
],
[
"modifyvm",
"{{.Name}}",
"--cpus",
"1"
]
]
}
],
"provisioners": [
{
"type": "powershell",
"elevated_user": "vagrant",
"elevated_password": "vagrant",
"environment_vars": [
"foo=bar",
"baz=bat"
],
"inline": [
"echo $env:PACKER_BUILD_NAME",
"echo $env:PACKER_BUILDER_TYPE",
"echo $env:foo",
"echo $env:baz",
"echo $env:foo > ~/foo.txt",
"echo $env:baz > ~/baz.txt"
]
},
{
"type": "powershell",
"valid_exit_codes": [
0,
200
],
"inline": [
"exit 200"
]
},
{
"type": "powershell",
"inline": [
"echo This should display"
]
},
{
"type": "powershell",
"inline": [
"exit 2"
]
},
{
"type": "powershell",
"inline": [
"echo This should NOT display!!!",
"exit 0"
]
}
]
}
@mefellows
Copy link
Author

Also works for the elevated shell runner, adding the following to the above json document will result in a build failure:

    {
      "type": "powershell",
      "elevated_user":     "vagrant",
      "elevated_password": "vagrant",
      "environment_vars":["foo=bar", "baz=bat"],
      "inline": [
        "exit 2"
      ]
    },
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment