Closed dtgm closed 8 years ago
Vagrantfile
$packageTestScript = <<SCRIPT
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}
SCRIPT
PS C:\dev\chocolatey-test-environment> vagrant provision
==> default: Running provisioner: shell...
default: Running: shell/PrepareWindows.ps1 as c:\tmp\vagrant-shell.ps1
==> default: IE Enhanced Security Configuration (ESC) has been disabled.
==> default: IE first run welcome screen has been disabled.
==> default: Setting Windows Update service to Manual startup type.
==> default: Running provisioner: shell...
default: Running: shell/InstallNet4.ps1 as c:\tmp\vagrant-shell.ps1
==> default: Running provisioner: shell...
default: Running: shell/InstallChocolatey.ps1 as c:\tmp\vagrant-shell.ps1
==> default: Chocolatey v0.9.10-beta1-151-ga83d5c5
==> default: Nothing to change. Config already set.
==> default: Chocolatey v0.9.10-beta1-151-ga83d5c5
==> default: Nothing to change. Config already set.
==> default: Chocolatey v0.9.10-beta1-151-ga83d5c5
==> default: Nothing to change. Config already set.
==> default: Running provisioner: shell...
default: Running: shell/NotifyGuiAppsOfEnvironmentChanges.ps1 as c:\tmp\vagrant-shell.ps1
==> default: 1
==> default:
==> default:
==> default: SUCCESS: Specified value was saved.
==> default: Running provisioner: shell...
default: Running: inline PowerShell script
So $LASTEXITCODE
!= 0
before the SCRIPT runs
last win32 application ran is setx.exe trigger 1
(?)
https://github.com/chocolatey/chocolatey-test-environment/blob/master/shell/NotifyGuiAppsOfEnvironmentChanges.ps1#L20
In above vagrant provision
output, setx.exe trigger 1
generates output line ==> default: SUCCESS: Specified value was saved.
So we could run a successful command before trying the pkg install
That makes sense. But why/how is $LASTEXITCODE being triggered in the script?
It doesn't look like setx.exe trigger 1
in shell\NotifyGuiAppsOfEnvironmentChanges.ps1
is achieving its intended effect.
Vagrantfile:
$packageTestScript = <<SCRIPT
if ($LASTEXITCODE -ne 0) {
exit 1
}
SCRIPT
PS C:\dev\chocolatey-test-environment> vagrant provision
==> default: Running provisioner: shell...
default: Running: shell/PrepareWindows.ps1 as c:\tmp\vagrant-shell.ps1
==> default: IE Enhanced Security Configuration (ESC) has been disabled.
==> default:
==> default: IE first run welcome screen has been disabled.
==> default:
==> default: Setting Windows Update service to Manual startup type.
==> default: Running provisioner: shell...
default: Running: shell/InstallNet4.ps1 as c:\tmp\vagrant-shell.ps1
==> default: Running provisioner: shell...
default: Running: shell/InstallChocolatey.ps1 as c:\tmp\vagrant-shell.ps1
==> default: Chocolatey v0.9.10-beta1-151-ga83d5c5
==> default: Nothing to change. Config already set.
==> default: Chocolatey v0.9.10-beta1-151-ga83d5c5
==> default: Nothing to change. Config already set.
==> default: Chocolatey v0.9.10-beta1-151-ga83d5c5
==> default: Nothing to change. Config already set.
==> default: Running provisioner: shell...
default: Running: shell/NotifyGuiAppsOfEnvironmentChanges.ps1 as c:\tmp\vagrant-shell.ps1
==> default: 1
==> default:
==> default: SUCCESS: Specified value was saved.
==> default: Running provisioner: shell...
default: Running: inline PowerShell script
The following WinRM command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!
powershell -ExecutionPolicy Bypass -OutputFormat Text -file c:\tmp\vagrant-shell.ps1
Stdout from the command:
Stderr from the command:
Vagrant seems to be running a win32 application that returns not 0 after running the shell\NotifyGuiAppsOfEnvironmentChanges.ps1
before running the user SCRIPT block.
Adding setx.exe trigger 1
inside the Vagrantfile SCRIPT block reverts whatever Vagrant is doing.
$packageTestScript = <<SCRIPT
setx.exe trigger 1 # sets $LASTEXITCODE to 0
if ($LASTEXITCODE -ne 0) {
exit 1
}
SCRIPT
PS C:\dev\chocolatey-test-environment> vagrant provision
==> default: Running provisioner: shell...
default: Running: shell/PrepareWindows.ps1 as c:\tmp\vagrant-shell.ps1
==> default: IE Enhanced Security Configuration (ESC) has been disabled.
==> default: IE first run welcome screen has been disabled.
==> default: Setting Windows Update service to Manual startup type.
==> default: Running provisioner: shell...
default: Running: shell/InstallNet4.ps1 as c:\tmp\vagrant-shell.ps1
==> default: Running provisioner: shell...
default: Running: shell/InstallChocolatey.ps1 as c:\tmp\vagrant-shell.ps1
==> default: Chocolatey v0.9.10-beta1-151-ga83d5c5
==> default: Nothing to change. Config already set.
==> default: Chocolatey v0.9.10-beta1-151-ga83d5c5
==> default: Nothing to change. Config already set.
==> default: Chocolatey v0.9.10-beta1-151-ga83d5c5
==> default: Nothing to change. Config already set.
==> default: Running provisioner: shell...
default: Running: shell/NotifyGuiAppsOfEnvironmentChanges.ps1 as c:\tmp\vagrant-shell.ps1
==> default: 1
==> default:
==> default: SUCCESS: Specified value was saved.
==> default: Running provisioner: shell...
default: Running: inline PowerShell script
==> default: SUCCESS: Specified value was saved.
Also, "SETX writes variables to the master environment in the registry."
It's about 1/5 second faster and probably more reliable to instead do
powershell -NoProfile -Command "exit 0"
NEVERMIND, not faster. setx in virtualbox is nearly instant.
it would actually be about 10x slower to use powershell -NoProfile -Command "exit 0"
host shell:
(measure-command {setx.exe trigger 1}).milliseconds
600
(measure-command {powershell -noprofile -command "exit 0"}).milliseconds
350
virtualbox shell:
(measure-command {setx.exe trigger 1}).milliseconds
23
(measure-command {powershell -noprofile -command "exit 0"}).milliseconds
209
That makes sense. But why/how is $LASTEXITCODE being triggered in the script?
Limitation of Vagrant/PowerShell - it doesn't catch errors when calling executables through PowerShell. The check fixes that.
why vagrant do that?
Vagrantfile https://github.com/chocolatey/chocolatey-test-environment/blob/master/Vagrantfile#L95-L108
vagrant provision
output