Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -on-error command line argument to allow preserving artifacts on builder errors #3885

Merged
merged 6 commits into from
Sep 20, 2016

Conversation

orivej
Copy link
Contributor

@orivej orivej commented Sep 14, 2016

This pull request resolves #409 by providing an option to delay or skip cleanup after unsuccessful packer build:

  -on-error=cleanup          When a builder fails, clean up and exit (the default)
  -on-error=abort            When a builder fails, abort without cleanup
  -on-error=ask              When a builder fails, prompt for action

Running with -on-error=ask:

==> qemu: Step "StepProvision" failed
==> qemu: [C]lean up and exit, [A]bort without cleanup, or [R]etry step (build may fail even if retry succeeds)? [car] |

@rickard-von-essen
Copy link
Collaborator

Looks interesting! This is missing some documentation. (Currently the build is busted, you can ignore Travis)

@orivej orivej force-pushed the on-error branch 5 times, most recently from 6d51023 to 897463e Compare September 14, 2016 01:22
@@ -157,7 +157,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
ui.Message(fmt.Sprintf("temp admin password: '%s'", b.config.Password))
}

b.runner = b.createRunner(&steps, ui)
b.runner = packerCommon.NewRunner(steps, b.config.PackerConfig, ui)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like how this code is simplified for every builder.

@boumenot
Copy link
Collaborator

Azure stuff LGTM. Thanks for the contribution.

@orivej orivej force-pushed the on-error branch 2 times, most recently from d584c09 to 3381f96 Compare September 16, 2016 12:13
@rickard-von-essen
Copy link
Collaborator

  1. We should fail on unknown values.
==> parallels-iso: Ignoring -on-error="ASK" argument: unknown on-error value

@orivej
Copy link
Contributor Author

orivej commented Sep 17, 2016

Done. Is the PR still missing some documentation?

Copy link
Collaborator

@rickard-von-essen rickard-von-essen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything works really great! I just have some comments about text and appearance. After they have been adjusted/discussed I would like to merge this, but I'd like the other maintainers to have a few days to also add their input.

steps[i] = askStep{step, ui}
}
default:
ui.Error(fmt.Sprintf("Ignoring -on-error=%q argument: unknown on-error value", config.PackerOnError))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should instead make packer exit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have already deleted the default clause since it can no longer happen. Now enumflag makes packer exit with an error like invalid value "ASK" for flag -on-error: expected one of ["cleanup" "abort" "ask"]

- `-only=foo,bar,baz` - Only build the builds with the given
comma-separated names. Build names by default are the names of their
builders, unless a specific `name` attribute is specified within
the configuration.

- `-parallel=false` - Disable parallelization of multiple builders (on by
default).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

- `-on-error=cleanup` (default), `-on-error=abort`, `-on-error=ask` - Selects
what to do when the build fails. `cleanup` cleans up after the previous
steps, deleting temporary files and virtual machines. `abort` exits without
any cleanup, but the next build may require `-force`. `ask` presents a
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

abort exits without any cleanup, but the next build may require -force.

Maybe rephrase to:

abort exits without any cleanup, which might require the next build to use -force.


func askPrompt(ui packer.Ui) askResponse {
for {
line, err := ui.Ask("[C]lean up and exit, [a]bort without cleanup, or [r]etry step (build may fail even if retry succeeds)?")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[C]lean up and exit, [a]bort without cleanup, or [r]etry step (build may fail even if retry succeeds)?

I think I ratter liked it to look like:

[c] Clean up and exit, [a] abort without cleanup, or [r] retry step (build may fail even if retry succeeds)?

Which makes it a bit more easy to read.

@@ -284,6 +288,9 @@ Options:
-except=foo,bar,baz Build all builds other than these
-force Force a build to continue if artifacts exist, deletes existing artifacts
-machine-readable Machine-readable output
-on-error=abort If the build fails, abort without cleanup
-on-error=ask If the build fails, prompt for action
-on-error=cleanup If the build fails, clean up and exit (the default)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer if they where on the same line, maybe:

-on-error=[cleanup|ask|abort] If the build fails do: clean up (default), ask, or abort

I think it's clear enough and the details are in the docs.

@rickard-von-essen
Copy link
Collaborator

Is the PR still missing some documentation?

No except for the comments I just gave I think this is done (and great).

@rickard-von-essen
Copy link
Collaborator

LGTM

Thanks for this great improvement!

@rickard-von-essen rickard-von-essen merged commit 13c9db5 into hashicorp:master Sep 20, 2016
@robmorgan
Copy link

thanks @orivej 👍

@gregorskii
Copy link
Contributor

gregorskii commented Oct 15, 2016

Hi,

This was merged into master 25 days ago, and the last release v0.10.2 was cut 16 days ago, but this update is not in the release 0.10.2 on the site, or in homebrew. I had to build from source to get it. Is this a known issue?

@rickard-von-essen
Copy link
Collaborator

rickard-von-essen commented Oct 15, 2016

It's not an issue, it's just read the CHANGELOG.md 😉 or:

 $ git log1 --graph --decorate=full -10 v0.10.2 v0.10.1                                                                                    14s  Sat Oct 15 22:25:18 2016
* 9e8a3fa (tag: refs/tags/v0.10.2) bump gem deps and www version
* fb1c968 Cut version 0.10.2
* 1414401 Cut version 0.10.2
* bb92eef Cut version 0.10.2
* 489c75a Go\'s -X linker flag now requires only one argument (#3540)
* 7bbc29d Fix go vet casing issue
* 8e7bb5e Change version.go to 0.10.1 release
| * 4e5f651 (tag: refs/tags/v0.10.1) Cut version 0.10.1
| * 2c27461 Change version.go to 0.10.1 release
|/
* aa47c90 Udpdated test/race timeouts to 2m because AWS seems to be taking a while

v0.10.2 is a rebuild of v0.10.1.

@gregorskii
Copy link
Contributor

Ah ok, will pay more attention to the change logs!. Will await 0.10.3. Also this feature works great. 👍

@orivej
Copy link
Contributor Author

orivej commented Oct 15, 2016

@gregorskii Thanks! Which mode do you use: abort, ask, or both?

@gregorskii
Copy link
Contributor

Currently ask, as I am debugging some googlecompute Ansible and Chef work, was pulling my hair out last weekend debugging roles as they would fail, and delete the instance before I could SSH in and poke around my work to see if the correct files and config was in place. Having ask when building out Packer files is a life saver.

@lklepner
Copy link

lklepner commented May 2, 2017

It would be great if -on-error=ask spit out a SSH key and IP addresses along with the prompt. This would make it easy to jump into the build to do some debugging prior to selecting cleanup or abort.

@petemounce
Copy link
Contributor

Similarly, for Windows, if the communicator is winrm and a password was generated, it would be really handy to dump that password to output so it can be used to log in to the failed build to inspect.

@SwampDragons
Copy link
Contributor

Given that the main conversation on this branch happened last year, it's a lot easier for us to track feature requests if you open a new ticket -- or, even better, a PR :)

@hashicorp hashicorp locked and limited conversation to collaborators Jun 28, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
core Core components of Packer enhancement pr/reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

--no-destroy-on-error like Vagrant
8 participants