feat(template): reboot VM before final shutdown+snapshot
This commit is contained in:
@@ -132,6 +132,18 @@ param(
|
||||
|
||||
[string] $DotNetSdkVersion = '10.0',
|
||||
|
||||
# Tier-2 Toolchain version pins — forwarded as-is to Setup-WinBuild2022.ps1
|
||||
[string] $Pwsh7Version = '7.6.1',
|
||||
[string] $NSISVersion = '3.12',
|
||||
[string] $CMakeVersion = '3.31.6',
|
||||
[string] $NodeJSVersion = '22.14.0',
|
||||
[string] $WiXVersion = '4.0.5',
|
||||
[string] $GhCliVersion = '2.92.0',
|
||||
[string] $VcpkgRef = '',
|
||||
|
||||
# Skip Tier-2 Toolchain — forwarded to Setup-WinBuild2022.ps1 -SkipTier2
|
||||
[switch] $SkipTier2,
|
||||
|
||||
[switch] $SkipWindowsUpdate,
|
||||
|
||||
# Skip disk cleanup inside the VM (cleanmgr + DISM + cache clear) — speeds up re-runs
|
||||
@@ -368,9 +380,17 @@ try {
|
||||
BuildUsername = $BuildUsername
|
||||
DotNetSdkVersion = $DotNetSdkVersion
|
||||
AdminPassword = $AdminPassword
|
||||
Pwsh7Version = $Pwsh7Version
|
||||
NSISVersion = $NSISVersion
|
||||
CMakeVersion = $CMakeVersion
|
||||
NodeJSVersion = $NodeJSVersion
|
||||
WiXVersion = $WiXVersion
|
||||
GhCliVersion = $GhCliVersion
|
||||
VcpkgRef = $VcpkgRef
|
||||
}
|
||||
if ($SkipWindowsUpdate) { $setupArgs['SkipWindowsUpdate'] = $true }
|
||||
if ($SkipCleanup) { $setupArgs['SkipCleanup'] = $true }
|
||||
if ($SkipTier2) { $setupArgs['SkipTier2'] = $true }
|
||||
|
||||
# ── Run Setup-WinBuild2022.ps1 inside the VM ──────────────────────────────
|
||||
# Setup may return exit 3010 (ERROR_SUCCESS_REBOOT_REQUIRED) when Windows
|
||||
@@ -570,6 +590,26 @@ try {
|
||||
$choice = Read-Host "[Prepare] Shut down VM and create snapshot '$SnapshotName'? [Y/N]"
|
||||
if ($choice -match '^[Yy]') {
|
||||
|
||||
# Reboot VM to flush any pending install state before final snapshot
|
||||
Write-Host "[Prepare] Rebooting VM to finalise installation state..."
|
||||
try {
|
||||
Invoke-Command -Session $session -ScriptBlock { Restart-Computer -Force } -ErrorAction SilentlyContinue
|
||||
}
|
||||
catch { }
|
||||
Remove-PSSession $session -ErrorAction SilentlyContinue
|
||||
$session = $null
|
||||
|
||||
Start-Sleep -Seconds 30 # let WinRM tear down before polling
|
||||
Write-Host "[Prepare] Waiting for guest WinRM to come back after reboot (max 10 min)..."
|
||||
if (-not (Wait-GuestWinRMReady -IP $VMIPAddress -Cred $credential `
|
||||
-SessionOptions $sessionOptions -TimeoutMin 10)) {
|
||||
throw "[Prepare] Guest did not come back after reboot within 10 min."
|
||||
}
|
||||
Write-Host "[Prepare] Guest WinRM ready after reboot." -ForegroundColor Green
|
||||
$session = New-PSSession -ComputerName $VMIPAddress -Credential $credential `
|
||||
-SessionOption $sessionOptions -UseSSL -Port 5986 `
|
||||
-Authentication Basic -ErrorAction Stop
|
||||
|
||||
# Send graceful shutdown
|
||||
Write-Host "[Prepare] Sending graceful shutdown to VM..."
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user