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

Commit seems to make this do what it should:

mfellows@matt.mit /private/tmp $ PACKER_LOG=true PACKER_LOG_PATH=./packer.log packer build ./packer.json
virtualbox-windows-ovf output will be in this color.

==> virtualbox-windows-ovf: Importing VM: output-basebox-vbox/talentsearch-api-1.0.0.ovf
==> virtualbox-windows-ovf: Creating forwarded port mapping for WinRM (host port 6226)
==> virtualbox-windows-ovf: Executing custom VBoxManage commands...
    virtualbox-windows-ovf: Executing: modifyvm packer-virtualbox-windows-ovf-1427687592 --memory 2048
    virtualbox-windows-ovf: Executing: modifyvm packer-virtualbox-windows-ovf-1427687592 --cpus 1
==> virtualbox-windows-ovf: Starting the virtual machine...
==> virtualbox-windows-ovf: Waiting 1m0s for boot...
==> virtualbox-windows-ovf: Typing the boot command...
==> virtualbox-windows-ovf: Waiting for WinRM to become available...
==> virtualbox-windows-ovf: Connected to WinRM!
==> virtualbox-windows-ovf: Uploading VirtualBox version info (4.3.20)
==> virtualbox-windows-ovf: Provisioning with Powershell...
==> virtualbox-windows-ovf: Provisioning with shell script: /var/folders/kf/4sgp93ys2t3_9t3yyzr07c3r0000gn/T/packer-powershell-provisioner711138473
    virtualbox-windows-ovf: virtualbox-windows-ovf
    virtualbox-windows-ovf: virtualbox-windows-ovf
    virtualbox-windows-ovf: bar
    virtualbox-windows-ovf: bat
    virtualbox-windows-ovf:
==> virtualbox-windows-ovf: Provisioning with Powershell...
==> virtualbox-windows-ovf: Provisioning with shell script: /var/folders/kf/4sgp93ys2t3_9t3yyzr07c3r0000gn/T/packer-powershell-provisioner678359207
==> virtualbox-windows-ovf: Provisioning with Powershell...
==> virtualbox-windows-ovf: Provisioning with shell script: /var/folders/kf/4sgp93ys2t3_9t3yyzr07c3r0000gn/T/packer-powershell-provisioner145581385
    virtualbox-windows-ovf: This
    virtualbox-windows-ovf: should
    virtualbox-windows-ovf: display
==> virtualbox-windows-ovf: Provisioning with Powershell...
==> virtualbox-windows-ovf: Provisioning with shell script: /var/folders/kf/4sgp93ys2t3_9t3yyzr07c3r0000gn/T/packer-powershell-provisioner667136397
    virtualbox-windows-ovf:
==> virtualbox-windows-ovf: Unregistering and deleting imported VM...
==> virtualbox-windows-ovf: Deleting output directory...
Build 'virtualbox-windows-ovf' errored: Script exited with non-zero exit status: 2. Allowed exit codes are: [%!s(int=0)]

==> Some builds didn't complete successfully and had errors:
--> virtualbox-windows-ovf: Script exited with non-zero exit status: 2. Allowed exit codes are: [%!s(int=0)]

==> Builds finished but no artifacts were created.

@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