diff --git a/Jenkinsfile b/Jenkinsfile index 2491cafc..ebdf9a01 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1172,7 +1172,7 @@ pipeline { node('docker && linux'){ def image checkout scm - timeout(60){ + timeout(120){ lock("${env.JOB_NAME} - ${env.NODE_NAME}"){ image = docker.build(UUID.randomUUID().toString(), '-f ci/docker/linux/tox/Dockerfile --build-arg PIP_EXTRA_INDEX_URL --build-arg PIP_INDEX_URL --build-arg UV_EXTRA_INDEX_URL --build-arg UV_INDEX_URL --build-arg PIP_DOWNLOAD_CACHE=/.cache/pip --build-arg UV_CACHE_DIR=/.cache/uv --build-arg CONAN_CENTER_PROXY_V2_URL .') } diff --git a/scripts/resources/windows/msvc/install_msvc.ps1 b/scripts/resources/windows/msvc/install_msvc.ps1 index 4152122b..12f4a593 100644 --- a/scripts/resources/windows/msvc/install_msvc.ps1 +++ b/scripts/resources/windows/msvc/install_msvc.ps1 @@ -159,6 +159,8 @@ function InstallMSVC{ [string]$VsInstallPath, [string]$ConfigFile ) + $updateProcesses = @("TiWorker", "TrustedInstaller") + $InstallerFile = "vs_buildtools.exe" Invoke-WebRequest $VsbuildtoolsURL -OutFile $InstallerFile Write-Host "Installing Visual Studio Build Tools to ${VsInstallPath}" @@ -237,7 +239,49 @@ function InstallMSVC{ } Write-Host "Cleaning up Package Cache - Done" + Write-Host "Checking for active Windows Update processes..." + + Get-WindowsUpdate + + # Check if any of these processes are actually running right now + $active = Get-Process -Name $updateProcesses -ErrorAction SilentlyContinue + + if ($active) { + $stopwatch = [System.Diagnostics.Stopwatch]::StartNew() + Write-Host "Update in progress. Waiting for completion..." + + # Loop while the processes are still active + while (Get-Process -Name $updateProcesses -ErrorAction SilentlyContinue) { + Get-Process -Name $updateProcesses -ErrorAction SilentlyContinue | Format-Table -AutoSize + Write-Host "Updating..." + + Start-Sleep -Seconds 30 + } + Write-Host "Windows Update processes have finished." + } else { + Write-Host "No active Windows Update detected. Exiting script." + } + + # ======== Wait for Windows Update to finish ======== + # It seems that installing MSVC build tools triggers Windows + # update. This generates a lot of extra unneeded files for + # the docker layer and bloats the image significantly. + # Waiting for the update to finish and then cleaning up the + # generated files seems to be the best solution to keep the + # layer size down. + + $timeout = New-TimeSpan -Hours 2 + $stopwatch = [System.Diagnostics.Stopwatch]::StartNew() + $installer = New-Object -ComObject Microsoft.Update.Installer + while ($installer.IsBusy) { + Write-Host "Windows Update is currently busy installing updates. Waiting..." + if ($stopwatch.Elapsed -gt $timeout) { + $stopwatch.Stop() + throw "Timeout exceeded: Operation took longer than 1 hour." + } + Start-Sleep -Seconds 30 + } # ======== Cleanup SoftwareDistribution folder ======== $SoftwareDistributionDownloadPath = "C:\Windows\SoftwareDistribution\Download" if (Test-Path "$SoftwareDistributionDownloadPath"){ @@ -340,6 +384,9 @@ function AddStartupScripts{ } +Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force +Install-Module PSWindowsUpdate -Force + # ========== Main ========== InstallMSVC ` -VsbuildtoolsURL $VSBUILDTOOLS_URLS[$VSVersion] `