Skip to content

Commit

Permalink
fix: add logs and retry logic for windows vhd building (#4680)
Browse files Browse the repository at this point in the history
  • Loading branch information
AbelHu authored Jul 23, 2024
1 parent afead9a commit 1804a30
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion vhdbuilder/packer/configure-windows-vhd.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,24 @@ function Register-ExpandVolumeTask {
'@

$taskScriptPath = Join-Path $global:aksToolsDir "expand-volume.ps1"
$taskScript| Set-Content -Path $taskScriptPath -Force
$taskScript | Set-Content -Path $taskScriptPath -Force

# It sometimes failed with below error
# New-ScheduledTask : Cannot validate argument on parameter 'Action'. The argument is null or empty. Provide an argument
# that is not null or empty, and then try the command again.
# Add below logs and retry logic to test it
$scriptContent = Get-Content -Path $taskScriptPath
Write-Log "Task script content: $scriptContent"

$action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-File `"$taskScriptPath`""
if (-not $action) {
Write-Log "action is null or empty. taskScriptPath: $taskScriptPath. Recreating it"
$action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-File `"$taskScriptPath`""
if (-not $action) {
Write-Log "action is still null"
exit 1
}
}
$principal = New-ScheduledTaskPrincipal -UserId SYSTEM -LogonType ServiceAccount -RunLevel Highest
$trigger = New-JobTrigger -AtStartup
$definition = New-ScheduledTask -Action $action -Principal $principal -Trigger $trigger -Description "aks-expand-volume"
Expand Down

0 comments on commit 1804a30

Please sign in to comment.