-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6762965
Add -on-error command line argument to allow preserving artifacts on …
orivej e9cc285
Document -on-error on the "packer build" page
orivej 115cb50
Document NewRunner
orivej 389603c
Allow upper case input to -on-error=ask
orivej 639bf35
Fail on unknown values of -on-error
orivej 4fe8624
Improve -on-error descriptions
orivej File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,11 +20,13 @@ type BuildCommand struct { | |
|
||
func (c BuildCommand) Run(args []string) int { | ||
var cfgColor, cfgDebug, cfgForce, cfgParallel bool | ||
var cfgOnError string | ||
flags := c.Meta.FlagSet("build", FlagSetBuildFilter|FlagSetVars) | ||
flags.Usage = func() { c.Ui.Say(c.Help()) } | ||
flags.BoolVar(&cfgColor, "color", true, "") | ||
flags.BoolVar(&cfgDebug, "debug", false, "") | ||
flags.BoolVar(&cfgForce, "force", false, "") | ||
flags.StringVar(&cfgOnError, "on-error", "cleanup", "") | ||
flags.BoolVar(&cfgParallel, "parallel", true, "") | ||
if err := flags.Parse(args); err != nil { | ||
return 1 | ||
|
@@ -99,12 +101,14 @@ func (c BuildCommand) Run(args []string) int { | |
|
||
log.Printf("Build debug mode: %v", cfgDebug) | ||
log.Printf("Force build: %v", cfgForce) | ||
log.Printf("On error: %v", cfgOnError) | ||
|
||
// Set the debug and force mode and prepare all the builds | ||
for _, b := range builds { | ||
log.Printf("Preparing build: %s", b.Name()) | ||
b.SetDebug(cfgDebug) | ||
b.SetForce(cfgForce) | ||
b.SetOnError(cfgOnError) | ||
|
||
warnings, err := b.Prepare() | ||
if err != nil { | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer if they where on the same line, maybe:
I think it's clear enough and the details are in the docs. |
||
-only=foo,bar,baz Only build the given builds by name | ||
-parallel=false Disable parallelization (on by default) | ||
-var 'key=value' Variable for templates, can be used multiple times. | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.