Merge pull request #43 from tristanbarcelon/develop

Add support for installing pipelines-agent binaries, but default to installing vsts-agent binaries
This commit is contained in:
Josh Wittner 2023-08-15 14:20:08 -07:00 коммит произвёл GitHub
Родитель 2b47484570 de484131d7
Коммит d48661ed26
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 37 добавлений и 17 удалений

Просмотреть файл

@ -91,6 +91,8 @@ function Get-Platform {
Find the latest available agent version. Find the latest available agent version.
.PARAMETER Platform .PARAMETER Platform
The platform required for the agent. The platform required for the agent.
.PARAMETER AgentType
Install Node6-based vsts-agent or Node10-based pipelines-agent asset
#> #>
function Find-VSTSAgent { function Find-VSTSAgent {
[CmdletBinding( DefaultParameterSetName = "NoVersion")] [CmdletBinding( DefaultParameterSetName = "NoVersion")]
@ -111,34 +113,36 @@ function Find-VSTSAgent {
[switch]$Latest, [switch]$Latest,
[parameter(Mandatory = $false)] [parameter(Mandatory = $false)]
[string]$Platform [string]$Platform = 'win',
[parameter(Mandatory = $false)]
[ValidateSet('vsts-agent','pipelines-agent')]
[string]$AgentType = 'vsts-agent'
) )
if ( $Latest ) { $rootUri = [uri]"https://github.com"
$findArgs = @{ } if ( $Latest ) {
if ( $Platform ) { $findArgs['Platform'] = $Platform } $releasesRelativeUri = [uri]"/Microsoft/vsts-agent/releases/latest"
$sortedAgents = Find-VSTSAgent @findArgs | Sort-Object -Descending -Property Version }
$sortedAgents | Where-Object { $_.Version -eq $sortedAgents[0].Version } else
return {
$releasesRelativeUri = [uri]"/Microsoft/vsts-agent/releases"
} }
Set-SecurityProtocol Set-SecurityProtocol
$rootUri = [uri]"https://github.com"
$releasesRelativeUri = [uri]"/Microsoft/vsts-agent/releases"
$page = [uri]::new( $rootUri, $releasesRelativeUri ) $page = [uri]::new( $rootUri, $releasesRelativeUri )
$queriedPages = @() $queriedPages = @()
do { do {
$result = Invoke-WebRequest $page -UseBasicParsing $result = Invoke-WebRequest $page -UseBasicParsing
$result.Links.href | Where-Object { $_ -match "vsts-agent-(\w+)-x64-(\d+\.\d+\.\d+)\..+$" } | ForEach-Object { $result.Links.href | Where-Object { $_ -match "$($AgentType)-$($Platform)-x64-(\d+\.\d+\.\d+)\..+$" } | ForEach-Object {
$instance = [PSCustomObject] @{ $instance = [PSCustomObject] @{
'Platform' = $Matches[1] 'Platform' = $Platform
'Version' = [VSTSAgentVersion]$Matches[2] 'Version' = [VSTSAgentVersion]$Matches[1]
'Uri' = [uri]::new($_, [System.UriKind]::RelativeOrAbsolute) 'Uri' = [uri]::new($_, [System.UriKind]::RelativeOrAbsolute)
} }
@ -148,7 +152,6 @@ function Find-VSTSAgent {
if ( $RequiredVersion -and $instance.Version -ne $RequiredVersion) { return } if ( $RequiredVersion -and $instance.Version -ne $RequiredVersion) { return }
if ( $MinimumVersion -and $instance.Version -lt $MinimumVersion) { return } if ( $MinimumVersion -and $instance.Version -lt $MinimumVersion) { return }
if ( $MaximumVersion -and $instance.Version -gt $MaximumVersion) { return } if ( $MaximumVersion -and $instance.Version -gt $MaximumVersion) { return }
if ( $Platform -and $instance.Platform -ne $Platform) { return }
Write-Verbose "Found agent at $($instance.Uri)" Write-Verbose "Found agent at $($instance.Uri)"
Write-Output $instance Write-Output $instance
@ -194,6 +197,8 @@ function Find-VSTSAgent {
What user credentials should be used by the agent service? What user credentials should be used by the agent service?
.PARAMETER Cache .PARAMETER Cache
Where should agent downloads be cached? Where should agent downloads be cached?
.PARAMETER AgentType
Install Node6-based vsts-agent or Node10-based pipelines-agent asset
#> #>
function Install-VSTSAgent { function Install-VSTSAgent {
[CmdletBinding(SupportsShouldProcess, DefaultParameterSetName = "NoVersion")] [CmdletBinding(SupportsShouldProcess, DefaultParameterSetName = "NoVersion")]
@ -253,7 +258,11 @@ function Install-VSTSAgent {
[pscredential]$LogonCredential, [pscredential]$LogonCredential,
[parameter(Mandatory = $false)] [parameter(Mandatory = $false)]
[string]$Cache = [io.Path]::Combine($env:USERPROFILE, ".vstsagents") [string]$Cache = [io.Path]::Combine($env:USERPROFILE, ".vstsagents"),
[parameter(Mandatory = $false)]
[ValidateSet('vsts-agent','pipelines-agent')]
[string]$AgentType = 'vsts-agent'
) )
if ($PSVersionTable.Platform -and $PSVersionTable.Platform -ne 'Win32NT') { if ($PSVersionTable.Platform -and $PSVersionTable.Platform -ne 'Win32NT') {
@ -274,6 +283,7 @@ function Install-VSTSAgent {
if ( $MinimumVersion ) { $findArgs['MinimumVersion'] = $MinimumVersion } if ( $MinimumVersion ) { $findArgs['MinimumVersion'] = $MinimumVersion }
if ( $MaximumVersion ) { $findArgs['MaximumVersion'] = $MaximumVersion } if ( $MaximumVersion ) { $findArgs['MaximumVersion'] = $MaximumVersion }
if ( $RequiredVersion ) { $findArgs['RequiredVersion'] = $RequiredVersion } if ( $RequiredVersion ) { $findArgs['RequiredVersion'] = $RequiredVersion }
if ( $AgentType ) { $findArgs['AgentType'] = $AgentType }
$agent = Find-VSTSAgent @findArgs | Sort-Object -Descending -Property Version | Select-Object -First 1 $agent = Find-VSTSAgent @findArgs | Sort-Object -Descending -Property Version | Select-Object -First 1
if ( -not $agent ) { throw "Could not find agent matching requirements." } if ( -not $agent ) { throw "Could not find agent matching requirements." }
@ -303,7 +313,17 @@ function Install-VSTSAgent {
Add-Type -AssemblyName System.IO.Compression.FileSystem -ErrorAction Stop Add-Type -AssemblyName System.IO.Compression.FileSystem -ErrorAction Stop
} }
[System.IO.Compression.ZipFile]::ExtractToDirectory($destPath, $agentFolder) if (Test-Path -Path $agentFolder -PathType Container) {
if ($PSCmdlet.ShouldProcess($agentFolder, "Overwriting with content of $($destPath)")) {
[System.IO.Compression.ZipFile]::ExtractToDirectory($destPath, $agentFolder, $true)
}
else {
throw "$($agentFolder) already exists."
}
}
else {
[System.IO.Compression.ZipFile]::ExtractToDirectory($destPath, $agentFolder)
}
$configPath = [io.path]::combine($agentFolder, 'config.cmd') $configPath = [io.path]::combine($agentFolder, 'config.cmd')
$configPath = Get-ChildItem $configPath -ErrorAction SilentlyContinue $configPath = Get-ChildItem $configPath -ErrorAction SilentlyContinue