Skip to content

Instantly share code, notes, and snippets.

@akanieski
Created July 21, 2022 16:34
Show Gist options
  • Save akanieski/77ef98baa96663657b75bce6fda1236e to your computer and use it in GitHub Desktop.
Save akanieski/77ef98baa96663657b75bce6fda1236e to your computer and use it in GitHub Desktop.
Update Azure DevOps Server App Tiers with Latest Agents
param (
[string] $Path
)
$RootDir = "C:\ProgramData\Microsoft\Azure DevOps\"
$AgentsCacheDirectory = "$RootDir\Agents"
if ($Path) {
$AgentsCacheDirectory = $Path
}
$LatestRelease = Invoke-RestMethod -Uri "https://api.github.com/repos/microsoft/azure-pipelines-agent/releases/latest"
Write-Output "Latest Release: $($LatestRelease.name)"
$LatestAssets = Invoke-RestMethod -Uri $LatestRelease.assets[0].browser_download_url
if (!(Test-Path $AgentsCacheDirectory))
{
New-Item -Path $RootDir -ItemType "directory" -Name "Agents"
}
if (Test-Path $AgentsCacheDirectory)
{
foreach ($ZippedAssetData in $LatestAssets)
{
$LocalZipPath = "$AgentsCacheDirectory\$($ZippedAssetData.name)"
$AlreadyExists = Test-Path -Path $LocalZipPath
if ($AlreadyExists)
{
Write-Output "$LocalZipPath ... Already Exists"
}
else
{
Write-Output "Starting download to $LocalZipPath ..."
Invoke-WebRequest -Uri $ZippedAssetData.downloadUrl -OutFile $LocalZipPath
Write-Output "Downloaded $LocalZipPath successfully"
}
}
}
else
{
Write-Output "[ERROR] Could find or write to $AgentsCacheDirectory."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment