Commit Graph

52 Commits

Author SHA1 Message Date
Wilken Rivera 2e326ef334 Switch back to call operator as opposed to dot sourcing
* Ensure child scope doesn't conflict with parent scope
* Add elevated user options to tests case.
2020-05-21 09:07:55 -04:00
Wilken Rivera 35df3914d2 provisioner/powershell: Update default execute command to handle script 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
```
2020-05-21 09:05:43 -04:00
Sylvia Moss 1c30a71d09
Replace file shared state by statebag (#9238) 2020-05-19 11:49:48 +02:00
Matt Kotsenas fe55494207
Add `debug_mode` to PowerShell provisioner (#8996) 2020-04-17 11:39:39 +02:00
Wilken Rivera 11db6014fa provisioner/powershell: Update remote clean up logic
* Add retry logic so that the provisioner will retry if it fails to upload/execute because of some restart provisioner step
* Add a testConfigWithSkipClean for testing that the provisioner executes the correct commands
* Add a test case for toggling the "skip_clean" config option
2020-04-08 00:23:40 -04:00
Megan Marsh bdcc95f989
fix execution policy parser to not interfere with legit integers, and add tests (#8997) 2020-04-07 10:32:58 +02:00
Megan Marsh 39fd462b56 change all provision func signatures to use map[string]interface{} 2019-12-12 15:38:32 -08:00
Megan Marsh 0ca7c9f397 fix tests 2019-12-11 16:29:35 -08:00
Adrien Delorme 819329228a Change back to make sure all durations are a time.Duration
It is simply the best/simplest solution and trying to prevent users from passing and integer here would be like opening a can of worms. Because:

* we cannot make mapstructure validate our duration string ( with an UnmarshalJSON func etc.)
* we cannot make mapstructure spit a string instead of a duration and packer will decode-encode-decode config.
* the hcl2 generated code asks for a string, so this will be enforced by default.
2019-10-31 16:12:07 +01:00
Adrien Delorme bf3d9841c6 Force durations to be passed a strings
Before this commit it was possible to set a duration using an integer or a float. Go's time.Duration is an int64 internally an mapstructure will take advantage of this and load the number as a int64 but `1` means one ns which is unexpected/confusing. To avoid confusion and enforce readability this forces users to pass a string with a unit for a duration; ex "56s".
2019-10-31 11:47:19 +01:00
Paul Meyer ec14ab4875 Add unit test to find issue #7655 2019-05-17 22:27:19 +00:00
Adrien Delorme d72040f4fa move retry code into the common/retry pkg and make retry context aware 2019-04-09 17:46:38 +02:00
Adrien Delorme c7ce4d598e change Provisioner to be passed a context for cancellation 2019-04-03 15:55:54 +02:00
Adrien Delorme a77ce59e36 Update provisioner_test.go
remove unecessary test
2019-03-14 12:48:21 +01:00
Matt Dainty 19bd28cd72 Fix/add tests 2018-12-07 16:23:03 +00:00
Matt Dainty 412119c27e Fix powershell provisioner tests 2018-11-09 14:26:21 +00:00
Megan Marsh 1d1729a5ff fix powershell tests to use new command 2018-10-12 09:54:27 -07:00
Megan Marsh a0edaf6c46 Going to revert this change for now, becuase of potential issues that arise from calling Prepare() twice
Revert "use statebag instead of SetSharedState for winRM password"

This reverts commit b35acbd879.
2018-09-10 16:48:42 -07:00
Megan Marsh b35acbd879 use statebag instead of SetSharedState for winRM password 2018-08-24 13:51:16 -07:00
DanHam b738f41efa
Remove tmp files created by provisioner/powershell tests 2018-04-30 20:38:03 +01:00
DanHam ccf687dac6
Fix tests 2018-04-24 11:10:35 +01:00
Josh Soref 24b4c36fc9 spelling: function 2018-03-13 07:52:02 +00:00
Megan Marsh f3a538db46 fix tests 2018-03-09 13:36:47 -08:00
Megan Marsh 3faf73b5f3 change backslashes to forward slashes in powershell provisioner; was breaking with cygwin 2018-03-09 09:29:29 -08:00
DanHam aaf7102b9a
Tests for escape of chars special to PowerShell in user supplied data 2018-02-08 12:03:18 +00:00
DanHam a7b118ed94
Fix tests post changes. Add test for upload func. 2018-02-08 12:03:18 +00:00
Megan Marsh addedbb680 Revert "Merge pull request #5515 from DanHam/dot-source-env-vars"
revert so we can use a branch that's had more recent work done
This reverts commit e56849c605, reversing
changes made to 6d14eb6ea4.
2018-02-02 09:58:39 -08:00
Megan Marsh 79fe900378 Revert "Merge pull request #5376 from DanHam/ps-escapes"
Revert so that we can merge a different branch that's had more recent work instead
This reverts commit ba518637d4, reversing
changes made to e56849c605.
2018-02-02 09:57:36 -08:00
DanHam b67c64fd66 Tests for escape of chars special to PowerShell in user supplied data 2018-02-01 13:19:07 -08:00
DanHam 4b89fc1c00
Fix tests post changes. Add test for upload func. 2017-10-30 21:08:14 +00:00
DanHam fa5fd602aa Fix tests post changes 2017-09-26 11:07:26 +01:00
Megan Marsh b05c673a14 Update powershell provisioner test with new default 2017-09-15 08:17:17 -07:00
Megan Marsh 89b058604d update tests for pull 5272 2017-08-22 14:20:40 -07:00
Luke Farnell d9a5b69403 clean up ineffectual assignments 2017-08-07 13:20:01 -04:00
Matthew Hooker 81522dced0
move packer to hashicorp 2017-04-04 13:39:01 -07:00
DanHam c88fafdf38 provisioner/powershell: align, fix and compact env var test 2017-01-23 12:10:46 +00:00
DanHam 80ebcea5e1
Mirror cleaner test code back from windows-shell to powershell 2017-01-19 13:33:59 +00:00
DanHam be0196492f
Tests for env variables values starting with or containing an equals sign 2016-12-28 00:31:17 +00:00
Taliesin Sisson f38d787b0e Powershell uses UTF16Le for encodedCommand 2016-12-12 22:44:56 +00:00
Taliesin Sisson e36051d394 Pattern for infrastructure changed to quote filename and execute file with ampersand as everything is run in powershell now
Handle powershell commands by specifying any extra infrastructure around running scripts inside of ExecuteCommand and ElevatedExecuteCommand
2016-12-12 22:44:55 +00:00
Taliesin Sisson d61513bf77 Encode powershell using utf8
Fix a bug in the size of string that was returned when decoding a base64 string
Added tests around encoding and decoding powershell scripts. Used [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes('powershell commands')) | clip to generate what base 64 strings should look like
2016-12-12 22:44:54 +00:00
Taliesin Sisson 17597b48e1 Base64 encode powershell to avoid any necessary escaping 2016-12-12 22:44:54 +00:00
Taliesin Sisson 5d5809b27e Make hiding of progress backward compatible with old versions of powershell 2016-12-12 22:44:48 +00:00
Taliesin Sisson e8c2b49be8 Use correct quotation of variables 2016-12-12 22:44:34 +00:00
Taliesin Sisson 4b394c8563 Write output will put ouput from function, so we don't want to be getting line from output of function
Fix unit tests for not showing progress stream when using powershell
Ensure that progress stream does not get leaked into stdout
Using Write-Output instead of Write-Host since PS v5 now leaks the host stream to stderr
2016-12-12 22:44:33 +00:00
Taliesin Sisson cd6213eb55 Seems like we do need to escape the double quote 2016-12-12 22:44:25 +00:00
Taliesin Sisson 15137310a7 Must escape string formatting for string fmt 2016-12-12 22:44:20 +00:00
Taliesin Sisson 5285a819dd Quoting of powershell commands and associated tests 2016-12-12 22:44:19 +00:00
Taliesin Sisson 3051ea6633 Quote powershell so that it does not try to interpret command to be run
Get VName out of state. This allows template replacement to be run on vmname
2016-12-12 22:44:10 +00:00
Rickard von Essen f17bd30070 Revert "Removed escaped quotes in non-elevated powershell invocation"
This reverts commit 1b186f1613.
2016-10-26 21:12:11 +02:00