hab: fix hab pipeline for windows (#7153)

Signed-off-by: Sonu Saha <sonu.saha@progress.com>
This commit is contained in:
Sonu Saha 2024-08-27 14:52:19 +05:30 committed by GitHub
parent e34d735e7a
commit 763c94862e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -15,12 +15,41 @@ $Properties = 'Caption', 'CSName', 'Version', 'BuildType', 'OSArchitecture'
Get-CimInstance Win32_OperatingSystem | Select-Object $Properties | Format-Table -AutoSize
Write-Host "--- Installing the version of Habitat required"
function Stop-HabProcess {
$habProcess = Get-Process hab -ErrorAction SilentlyContinue
if ($habProcess) {
Write-Host "Stopping hab process..."
Stop-Process -Name hab -Force
}
}
function Install-Habitat {
Write-Host "Downloading and installing Habitat..."
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/habitat-sh/habitat/main/components/hab/install.ps1'))
}
try {
hab --version
}
catch {
Set-ExecutionPolicy Bypass -Scope Process -Force
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/habitat-sh/habitat/main/components/hab/install.ps1'))
Stop-HabProcess
# Remove the existing hab.exe if it exists and if you have permissions
$habPath = "C:\ProgramData\Habitat\hab.exe"
if (Test-Path $habPath) {
Write-Host "Attempting to remove existing hab.exe..."
Remove-Item $habPath -Force -ErrorAction SilentlyContinue
if (Test-Path $habPath) {
Write-Host "Failed to remove hab.exe, re-running script with elevated permissions."
Start-Process powershell -Verb runAs -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`""
exit
}
}
Install-Habitat
}
finally {
Write-Host ":habicat: I think I have the version I need to build."