Wilken Rivera
1e90165a56
Add source URL to test fixture script ( #9296 )
2020-05-26 10:24:12 -04:00
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
38f799df3e
Add conditional to check if LastExitCode is defined
...
* Add broken requires statement test case
* Add test case to reproduce invalid LastExitCode
2020-05-21 09:07:43 -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
Wilken Rivera
13e0c1a097
tests/provisioner/powershell: Add acceptance test to reproduce issue 4916
2020-05-21 09:05:43 -04:00
Wilken Rivera
fe721d8e11
test/provisioner/powershell: Add acceptance test for powershell provisioner cleanup
...
Passing Tests
```
--- PASS: TestAccPowershellProvisioner_basic (282.02s)
--- PASS: TestAccPowershellProvisioner_basic/testing_amazon-ebs_builder_against_powershell_provisioner (282.01s) PASS
ok github.com/hashicorp/packer/provisioner/powershell 282.046s
```
Failing tests on master
```
2020/04/08 09:59:34 Uploading file to 'c:/Windows/Temp/script.bat'
2020/04/08 09:59:36 [INFO] starting remote command: set "PACKER_BUILDER_TYPE=amazon-ebs" && set "PACKER_BUILD_NAME=amazon-ebs"
&& "c:/Windows/Temp/script.bat"
2020/04/08 09:59:36 ui: amazon-ebs:
2020/04/08 09:59:36 ui: amazon-ebs: C:\Users\Administrator>dir C:\Windows\Temp\packer-*.ps1
2020/04/08 09:59:36 ui: amazon-ebs: Volume in drive C has no label.
2020/04/08 09:59:36 [INFO] command 'set "PACKER_BUILDER_TYPE=amazon-ebs"
&& set "PACKER_BUILD_NAME=amazon-ebs" && "c:/Windows/Temp/script.bat"' exited with code: 0
2020/04/08 09:59:36 ui: amazon-ebs: Volume Serial Number is 46CA-4083
2020/04/08 09:59:36 ui: amazon-ebs:
2020/04/08 09:59:36 ui: amazon-ebs: Directory of C:\Windows\Temp
2020/04/08 09:59:36 ui: amazon-ebs:
2020/04/08 09:59:36 ui: amazon-ebs: 04/08/2020 01:59 PM 102 packer-acc-test-script-test.ps1
2020/04/08 09:59:36 ui: amazon-ebs: 04/08/2020 01:59 PM 76 packer-acc-test-vars.ps1
2020/04/08 09:59:36 ui: amazon-ebs: 2 File(s) 178 bytes
2020/04/08 09:59:36 ui: amazon-ebs: 0 Dir(s) 9,735,806,976 bytes free
2020/04/08 09:59:36 ui: ==> amazon-ebs: Provisioning step had errors: Running the cleanup provisioner, if present...
2020/04/08 09:59:36 ui: ==> amazon-ebs: Terminating the source AWS instance...
2020/04/08 10:00:09 ui: ==> amazon-ebs: Cleaning up any extra volumes...
2020/04/08 10:00:09 ui: ==> amazon-ebs: No volumes to clean up, skipping
2020/04/08 10:00:09 ui: ==> amazon-ebs: Deleting temporary security group...
2020/04/08 10:00:10 ui: ==> amazon-ebs: Deleting temporary keypair...
2020/04/08 10:00:11 ui error: Build 'amazon-ebs' errored: Script exited
with non-zero exit status: 0.Allowed exit codes are: [1]
2020/04/08 10:00:11 machine readable: error-count []string{"1"}
2020/04/08 10:00:11 ui error:
==> Some builds didn't complete successfully and had errors:
2020/04/08 10:00:11 machine readable: amazon-ebs,error []string{"Script
exited with non-zero exit status: 0.Allowed exit codes are: [1]"}
2020/04/08 10:00:11 ui error: --> amazon-ebs: Script exited with
non-zero exit status: 0.Allowed exit codes are: [1]
```
test: Fix windows-shell command
2020-04-08 10:05:54 -04:00
Wilken Rivera
b183c5498f
provisioner/powershell: Add basic Powershell provisioner acceptance tests
...
* Modifies the amazon-ebs builder with a windows build configuration
```
⇶ ACC_TEST_BUILDERS=amazon-ebs ACC_TEST_PROVISIONERS=powershell go test -v ./provisioner/powershell/... -run=TestPowershellProvisioner_Inline
--- PASS: TestPowershellProvisioner_Inline (256.50s)
--- PASS: TestPowershellProvisioner_Inline/testing_amazon-ebs_builder_against_powershell_provisioner (256.50s)
PASS
ok github.com/hashicorp/packer/provisioner/powershell 256.525s
```
2020-04-06 16:52:05 -04:00