| steps: |
| - powershell: | |
| $pythonPath = 'C:\Python39' |
| $pythonInstallerLogPath = 'python_installer.log' |
| $installArgs = "/passive /log $pythonInstallerLogPath TargetDir=$pythonPath" |
| |
| Write-Host "Downloading python installer exe" |
| $downloadPath = 'python_installer.exe' |
| Start-BitsTransfer -Source https://www.python.org/ftp/python/3.9.4/python-3.9.4-amd64.exe -Destination $downloadPath |
| $hash = (Get-FileHash $downloadPath).Hash.ToLower() |
| $expectedHash = "58e6bb9d08fd250c1defb7a7a7247993b4ea349518ba877abb6364de85029e04" |
| if ($hash.Equals($expectedHash)) { |
| Write-Host "$downloadPath hash verified" |
| } else { |
| Throw "$downloadPath hash mismatch, got $hash, expected $expectedHash" |
| } |
| |
| if (Test-Path -LiteralPath $pythonPath) { |
| Write-Host "$pythonPath already exists, uninstall it" |
| $uninstallArgs = $installArgs + " /uninstall /quiet" |
| $p = Start-Process -FilePath $downloadPath -Verb RunAs -ArgumentList $uninstallArgs -PassThru -Wait |
| Write-Host "Uninstall finished. Exit code was: $($p.ExitCode)" |
| } |
| |
| Write-Host "Running $downloadPath with args $installArgs" |
| $p = Start-Process -FilePath $downloadPath -Verb RunAs -ArgumentList $installArgs -PassThru -Wait |
| Write-Host "$downloadPath finished. Exit code was: $($p.ExitCode)" |
| |
| Write-Host "Adding Python dirs to path" |
| Write-Host "##vso[task.prependpath]C:\Python39" |
| Write-Host "##vso[task.prependpath]C:\Python39\Scripts" |
| |
| Write-Host "Dumping install log file:" |
| Get-Content -Path "python_installer.log" |
| displayName: 'Install Python (Windows)' |
| condition: and(succeeded(), eq(variables['Agent.OS'], 'Windows_NT')) |