-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-LatestAzurePipelineAgent.ps1
More file actions
62 lines (47 loc) · 2.48 KB
/
Copy pathGet-LatestAzurePipelineAgent.ps1
File metadata and controls
62 lines (47 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<#
.SYNOPSIS
Download latest Azure Pipelines agent
.DESCRIPTION
Downloads the latest Azure Pipelines agent from GitHub
.PARAMETER Platform
Specify the platform for which you need to download an agent (win-x86, win-x64, osx-64, linux-x64, linux-arm, linux-arm64, rhel.6-x64).
.PARAMETER DownloadFolder
Specify the folder you want to download the agent to. If this parameter is omitted, the current working directory is used.
.PARAMETER ExcludeNode6
Specify this switch to exclude Node6 runtime from the agent.
.EXAMPLE
.\Get-LatestAzurePipelinesAgent.ps1 -Platform win-x64
Downloads the latest Azure Pipelines agent for the Windows x64 platform to the current working directory.
.EXAMPLE
.\Get-LatestAzurePipelinesAgent.ps1 -Platform linux-x64 -ExcludeNode6 -DownloadFolder /azagents
Downloads the latest Azure Pipelines agent that does not include the Node6 runtime for the Linux x64 platform to the folder /azagents.
#>
[CmdletBinding()]
param (
[Parameter(Mandatory = $true, HelpMessage = "Specify the platform for which you need to download an agent (win-x86, win-x64, osx-64, linux-x64, linux-arm, linux-arm64, rhel.6-x64).")]
[ValidateSet("win-x86", "win-x64", "osx-64", "linux-x64", "linux-arm", "linux-arm64", "rhel.6-x64")]
[string] $Platform,
[Parameter(Mandatory = $false, HelpMessage = "Specify the folder you want to download the agent to. If this parameter is omitted, the current working directory is used.")]
[string] $DownloadFolder = $PWD,
[Parameter(Mandatory = $false, HelpMessage = "Specify this switch to exclude Node6 runtime from the agent.")]
[switch] $ExcludeNode6
)
$agentReleasesUri = "https://api.github.com/repos/microsoft/azure-pipelines-agent/releases/latest"
$latestAgentInfo = Invoke-RestMethod $agentReleasesUri
$assets = Invoke-RestMethod $latestAgentInfo.assets[0].browser_download_url
$platformAgents = $assets | Where-Object { $_.platform -eq $Platform }
$agent = $null
if ($ExcludeNode6) {
$agent = $platformAgents | Where-Object { $_.name.StartsWith("pipelines") }
} else {
$agent = $platformAgents | Where-Object { $_.name.StartsWith("vsts") }
}
if ($agent) {
$outFile = Join-Path $DownloadFolder ([System.IO.Path]::GetFileName($agent.downloadUrl))
Write-Host "Downloading latest $Platform agent to $outFile..."
Invoke-WebRequest $agent.downloadUrl -OutFile $outFile | Out-Null
Write-Host "Done"
} else {
Write-Host "ERROR: Invalid asset information" -ForegroundColor Red
exit 1
}