provisioner/powershell: Update default execute command to handle script errors#9040
provisioner/powershell: Update default execute command to handle script errors#9040SwampDragons merged 4 commits intomasterfrom
Conversation
Codecov Report
|
|
This probably needs to go into 1.6 since it's going to change behavior. |
|
I tested this and it looks good. Not merging yet since this is targeted for v1.6 |
3cdfb89 to
e396f4e
Compare
aee26ca to
92d8ba0
Compare
SwampDragons
left a comment
There was a problem hiding this comment.
one small question but otherwise this looks great :)
| } | ||
|
|
||
| baseCmd += `. {{.Vars}}; &'{{.Path}}'; exit $LastExitCode }` | ||
| baseCmd = fmt.Sprintf(baseCmd, debugLine) |
There was a problem hiding this comment.
this doesn't look like a valid fmt.Sprintf string to me.
There was a problem hiding this comment.
In my PR I added a hard to see string interpolation verb at the beginning of the line %s. {{.Vars}}; ... }. But that is confusing for sure so I reformatted it back to how it was.
There was a problem hiding this comment.
oh yeah I totally missed that, sorry.
…pt errors This change sets the ErrorActionPreference and wraps the script execution in a Try/Catch statement so that the provisioner can capture any errors encountered when running the script. In addition to the try/catch the `&` operator is replaced by the `.` sourcing operator to ensure the script is executed in the same scope as the parent command (so that errors bubble up properly). Tests after change ``` ⇶ ACC_TEST_BUILDERS=amazon-ebs ACC_TEST_PROVISIONERS=powershell go test ./provisioner/powershell/... -timeout=1h ok github.com/hashicorp/packer/provisioner/powershell 915.865s ```
* Add broken requires statement test case * Add test case to reproduce invalid LastExitCode
* Ensure child scope doesn't conflict with parent scope * Add elevated user options to tests case.
e188ce9 to
2e326ef
Compare
…er-9040 Revert "Merge pull request #9040 from hashicorp/powershell-exit-code-fix-4916"
|
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
This change sets the ErrorActionPreference and wraps the script execution in a Try/Catch statement so that the provisioner can capture any errors encountered when running the script. In addition to the try/catch the
&operator is replaced by the.sourcing operator to ensure the script is executed in the same scope as the parent command (so that errors bubble up properly).Tests after change
Todo
Closes #4916
Closes #9161