From 0a51687b6566f028e6fc2fcff1ab6301abf4b12e Mon Sep 17 00:00:00 2001 From: leileizhang Date: Wed, 19 Feb 2025 09:17:15 +0800 Subject: [PATCH] [CI] fix: Use Azure CLI for artifact download to prevent OutOfMemory issues (#37455) * for testing az * change file * update test * install python * update * test * use powershell * tes * update enve * update * test * add * test * merge * az * change * update * test cli * add debug * test large * fix * use templete * fix x64 python install * for testing * add * fix * use 3.11.1 * change for test * revert some testing file * update the file name for spelling check * use azure cli zip * use aka.ms * rename the zip file --- .pipelines/v2/templates/job-build-project.yml | 23 +++---------- .pipelines/v2/templates/job-test-project.yml | 12 +++---- ...teps-download-artifacts-with-azure-cli.yml | 33 +++++++++++++++++++ 3 files changed, 41 insertions(+), 27 deletions(-) create mode 100644 .pipelines/v2/templates/steps-download-artifacts-with-azure-cli.yml diff --git a/.pipelines/v2/templates/job-build-project.yml b/.pipelines/v2/templates/job-build-project.yml index f5bb7300be..f55d9f71a9 100644 --- a/.pipelines/v2/templates/job-build-project.yml +++ b/.pipelines/v2/templates/job-build-project.yml @@ -456,12 +456,6 @@ jobs: Copy-Item src\gpo\assets\* "$(JobOutputDirectory)/gpo" -Recurse displayName: Stage GPO files - - ${{ if eq(parameters.publishArtifacts, true) }}: - - publish: $(JobOutputDirectory) - artifact: $(JobOutputArtifactName) - displayName: Publish all outputs - condition: always() - # Running the tests may result in future jobs consuming artifacts out of this build - ${{ if eq(parameters.runTests, true) }}: - task: CopyFiles@2 @@ -471,17 +465,8 @@ jobs: contents: '$(BuildPlatform)/$(BuildConfiguration)/**/*' targetFolder: '$(JobOutputDirectory)\$(BuildPlatform)\$(BuildConfiguration)' - - task: CopyFiles@2 - displayName: Stage entire build output - inputs: - sourceFolder: $(JobOutputDirectory) - contents: |- - ** - !**\*.pdb - !**\*.lib - targetFolder: '$(JobOutputDirectory)\TestArtifacts' - - - publish: $(JobOutputDirectory)\TestArtifacts - artifact: $(JobOutputArtifactName)-TestArtifacts - displayName: Publish all outputs for testing + - ${{ if eq(parameters.publishArtifacts, true) }}: + - publish: $(JobOutputDirectory) + artifact: $(JobOutputArtifactName) + displayName: Publish all outputs condition: always() diff --git a/.pipelines/v2/templates/job-test-project.yml b/.pipelines/v2/templates/job-test-project.yml index 81c687ad4a..c2e7bb4e7d 100644 --- a/.pipelines/v2/templates/job-test-project.yml +++ b/.pipelines/v2/templates/job-test-project.yml @@ -19,7 +19,7 @@ jobs: BuildPlatform: ${{ parameters.platform }} BuildConfiguration: ${{ parameters.configuration }} SrcPath: $(Build.Repository.LocalPath) - TestArtifactsName: build-${{ parameters.platform }}-${{ parameters.configuration }}${{ parameters.inputArtifactStem }}-TestArtifacts + TestArtifactsName: build-${{ parameters.platform }}-${{ parameters.configuration }}${{ parameters.inputArtifactStem }} pool: ${{ if eq(variables['System.CollectionId'], 'cb55739e-4afe-46a3-970f-1b49d8ee7564') }}: ${{ if ne(parameters.platform, 'ARM64') }}: @@ -61,13 +61,9 @@ jobs: reg add "HKLM\Software\Policies\Microsoft\Edge\WebView2\ReleaseChannels" /v PowerToys.exe /t REG_SZ /d "3" displayName: "Enable WebView2 Canary Channel" - - download: current - displayName: Download artifacts - artifact: $(TestArtifactsName) - patterns: |- - ** - !**\*.pdb - !**\*.lib + - template: steps-download-artifacts-with-azure-cli.yml + parameters: + artifactName: $(TestArtifactsName) - template: steps-ensure-dotnet-version.yml parameters: diff --git a/.pipelines/v2/templates/steps-download-artifacts-with-azure-cli.yml b/.pipelines/v2/templates/steps-download-artifacts-with-azure-cli.yml new file mode 100644 index 0000000000..b8f0401cfc --- /dev/null +++ b/.pipelines/v2/templates/steps-download-artifacts-with-azure-cli.yml @@ -0,0 +1,33 @@ +parameters: +- name: artifactName + type: string + default: "" + +# Why use az cli to download? → The ARM agent may run into OutOfMemory issues. +# Why use the Azure CLI ZIP version? → It comes with its own Python and works fine under emulation on ARM64. +# Why not use AzureCLI@2 task? → It requires azureSubscription, which is unnecessary for downloading artifacts. + +steps: +- powershell: | + Write-Host "Downloading Azure CLI ZIP..." + $azCliUrl = "https://aka.ms/installazurecliwindowszipx64" + $azCliZip = "$(Build.ArtifactStagingDirectory)\azure-cli.zip" + + Invoke-WebRequest -Uri $azCliUrl -OutFile $azCliZip + displayName: 'Install Azure CLI from ZIP' + +- task: ExtractFiles@1 + inputs: + archiveFilePatterns: '$(Build.ArtifactStagingDirectory)\azure-cli.zip' + destinationFolder: '$(Build.ArtifactStagingDirectory)\AzureCLI' + +- pwsh: | + $azureCliPath = "$(Build.ArtifactStagingDirectory)\AzureCLI\bin" + $env:Path = "$azureCliPath;" + $env:Path + Write-Host "Configuring Azure DevOps defaults..." + az devops configure --defaults organization='$(System.TeamFoundationCollectionUri)' project='$(System.TeamProject)' --use-git-aliases true + Write-Host "Downloading artifacts..." + az pipelines runs artifact download --artifact-name ${{parameters.artifactName}} --path "$(Pipeline.Workspace)/${{parameters.artifactName}}" --run-id $(Build.BuildId) --debug + displayName: 'Download artifacts with Azure CLI' + env: + AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)