mirror of
https://github.com/inspec/inspec
synced 2024-11-10 07:04:15 +00:00
hab: fix hab pipeline for windows (#7152)
Signed-off-by: Sonu Saha <sonu.saha@progress.com>
This commit is contained in:
parent
efd97f589f
commit
b8ee7eae07
1 changed files with 30 additions and 1 deletions
|
@ -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."
|
||||
|
|
Loading…
Reference in a new issue