diff --git a/containers/agent-windows-buildkite/Dockerfile b/containers/agent-windows-buildkite/Dockerfile index 14714d6..09faf0c 100644 --- a/containers/agent-windows-buildkite/Dockerfile +++ b/containers/agent-windows-buildkite/Dockerfile @@ -4,5 +4,8 @@ ARG agent_windows_version=latest FROM gcr.io/llvm-premerge-checks/agent-windows-vs2019:${agent_windows_version} +RUN choco install -y handle --checksum 524E61547C8E26608CDA1B11B6E9471616CCCC48530F6E7EC9131EABF839357E COPY start_agent.ps1 C:\scripts\ +COPY pre-checkout.bat c:\buildkite-agent\hooks\ +COPY unlock_path.ps1 c:\scripts CMD "powershell C:\scripts\start_agent.ps1" \ No newline at end of file diff --git a/containers/agent-windows-buildkite/VERSION b/containers/agent-windows-buildkite/VERSION index b4de394..9d1294d 100644 Binary files a/containers/agent-windows-buildkite/VERSION and b/containers/agent-windows-buildkite/VERSION differ diff --git a/containers/agent-windows-buildkite/pre-checkout.bat b/containers/agent-windows-buildkite/pre-checkout.bat new file mode 100644 index 0000000..a0d12aa --- /dev/null +++ b/containers/agent-windows-buildkite/pre-checkout.bat @@ -0,0 +1,2 @@ +handle -nobanner %BUILDKITE_BUILD_CHECKOUT_PATH% +powershell c:\scripts\unlock_path.ps1 %BUILDKITE_BUILD_CHECKOUT_PATH% \ No newline at end of file diff --git a/containers/agent-windows-buildkite/unlock_path.ps1 b/containers/agent-windows-buildkite/unlock_path.ps1 new file mode 100644 index 0000000..8572c61 --- /dev/null +++ b/containers/agent-windows-buildkite/unlock_path.ps1 @@ -0,0 +1,34 @@ +# Based ob https://dandraka.com/2019/08/13/find-and-kill-processes-that-lock-a-file-or-directory/ +$path = $args[0] +$handleOutput = & handle -a $path + +if ($handleOutput -match "no matching handles found") { + Write-Host "Nothing to kill, exiting" + exit +} + +$pidList = New-Object System.Collections.ArrayList +$lines = $handleOutput -split "`n" +foreach($line in $lines) { + # sample line: + # chrome.exe pid: 11392 type: File 5BC: C:\Windows\Fonts\timesbd.ttf + # regex to get pid and process name: (.*)\b(?:.*)(?:pid: )(\d*) + $matches = $null + $line -match "(.*)\b(?:.*)(?:pid: )(\d*)" | Out-Null + if (-not $matches) { continue } + if ($matches.Count -eq 0) { continue } + $pidName = $matches[1] + $pidStr = $matches[2] + if ($pidList -notcontains $pidStr) { + Write-Host "Will kill process $pidStr $pidName" + $pidList.Add($pidStr) | Out-Null + } +} + +foreach($pidStr in $pidList) { + $pidInt = [int]::Parse($pidStr) + Stop-Process -Id $pidInt -Force + Write-Host "Killed process $pidInt" +} + +Write-Host "Finished" \ No newline at end of file diff --git a/scripts/steps.py b/scripts/steps.py index f5017df..0b0024d 100644 --- a/scripts/steps.py +++ b/scripts/steps.py @@ -91,8 +91,6 @@ def generic_linux(projects: str, check_diff: bool) -> List: def generic_windows(projects: str) -> List: - # TODO: windows builds are temporary disabled #243 - return [] if os.getenv('ph_skip_windows') is not None: return [] scripts_refspec = os.getenv("ph_scripts_refspec", "master") @@ -138,7 +136,7 @@ def generic_windows(projects: str) -> List: ], 'artifact_paths': ['artifacts/**/*', '*_result.json'], 'agents': win_agents, - 'timeout_in_minutes': 120, + 'timeout_in_minutes': 90, 'retry': {'automatic': [ {'exit_status': -1, 'limit': 2}, # Agent lost {'exit_status': 255, 'limit': 2}, # Forced agent shutdown