diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 3809be44c13..609a0141c14 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -180,11 +180,16 @@ jobs: displayName: Test Windows MSI dependsOn: BuildWindowsMSI - # condition: and(succeeded(), in(variables['Build.Reason'], 'IndividualCI', 'BatchedCI', 'Manual', 'Schedule')) - condition: false + condition: and(succeeded(), in(variables['Build.Reason'], 'IndividualCI', 'BatchedCI', 'Manual', 'Schedule')) pool: vmImage: 'vs2017-win2016' steps: + - task: DownloadPipelineArtifact@1 + displayName: 'Download Build Artifacts' + inputs: + TargetPath: '$(Build.ArtifactStagingDirectory)/metadata' + artifactName: metadata + - task: DownloadPipelineArtifact@1 displayName: 'Download Build Artifacts' inputs: @@ -196,16 +201,38 @@ jobs: inputs: targetType: inline script: | + if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { + # Start another Powershell process as Admin and execute this script again + $arguments = "& '" +$myinvocation.mycommand.definition + "'" + Start-Process powershell -Verb runAs -ArgumentList $arguments + # Stop if the PowerShell is not run as Admin + Break + } + # The following are executed by elevated PowerShell + az --version + $InstallArgs = @( - "/I" - '"$env:SYSTEM_ARTIFACTSDIRECTORY/msi/Microsoft Azure CLI.msi"' + "/i" + "`"$env:SYSTEM_ARTIFACTSDIRECTORY\msi\Microsoft Azure CLI.msi`"" + "/q" "/norestart" - "/L*v" + "/l*v" ".\install_logs.txt" ) + $pre_installed_version=az version --query '\"azure-cli\"' -o tsv + $to_be_installed_version=Get-Content $(System.ArtifactsDirectory)/metadata/version + if ($pre_installed_version -eq $to_be_installed_version){ + # See https://docs.microsoft.com/windows/win32/msi/reinstallmode about options of REINSTALLMODE + $reinstall_option="REINSTALL=ALL REINSTALLMODE=emus" + $InstallArgs += $reinstall_option + } Start-Process "msiexec.exe" -ArgumentList $InstallArgs -Wait -NoNewWindow Get-Content .\install_logs.txt - + $installed_version=az version --query '\"azure-cli\"' -o tsv + if ($installed_version -ne $to_be_installed_version){ + echo "The MSI failed to install." + Exit 1 + } az --version az self-test diff --git a/build_scripts/windows/scripts/build.cmd b/build_scripts/windows/scripts/build.cmd index a819bf1d625..c5987943202 100644 --- a/build_scripts/windows/scripts/build.cmd +++ b/build_scripts/windows/scripts/build.cmd @@ -83,7 +83,7 @@ if not exist %PYTHON_DIR% ( popd ) set PYTHON_EXE=%PYTHON_DIR%\python.exe -%PYTHON_EXE% -m pip install --upgrade pip==21.0.1 +%PYTHON_EXE% -m pip install --upgrade pip==21.0.1 setuptools==52.0.0 robocopy %PYTHON_DIR% %BUILDING_DIR% /s /NFL /NDL @@ -146,10 +146,26 @@ for /f %%f in ('dir /b /s *.pyc') do ( ) popd +:: Remove __pycache__ +echo remove pycache for /d /r %BUILDING_DIR%\Lib\site-packages\pip %%d in (__pycache__) do ( if exist %%d rmdir /s /q "%%d" ) +:: Remove aio +echo remove aio +for /d /r %BUILDING_DIR%\Lib\site-packages\azure\mgmt %%d in (aio) do ( + if exist %%d rmdir /s /q "%%d" +) + +:: Remove dist-info +echo remove dist-info +pushd %BUILDING_DIR%\Lib\site-packages +for /d %%d in ("*.dist-info") do ( + if exist %%d rmdir /s /q "%%d" +) +popd + if %errorlevel% neq 0 goto ERROR ::ensure propagate_env_change.exe is available