mirror of
https://github.com/tribufu/ServerManagers
synced 2026-05-06 15:17:34 +00:00
Update azure-pipelines.yml for Azure Pipelines
This commit is contained in:
parent
8a479ae2aa
commit
d1b5af9e83
1 changed files with 38 additions and 52 deletions
|
|
@ -43,85 +43,71 @@ stages:
|
|||
inputs:
|
||||
targetType: 'inline'
|
||||
script: |
|
||||
Function Get-AzureDevopsBuild() {
|
||||
param(
|
||||
[Parameter(Mandatory = $true)] [string]$baseUri,
|
||||
[Parameter(Mandatory = $true)] [string]$accessToken,
|
||||
[Parameter(Mandatory = $true)] [int]$buildId
|
||||
)
|
||||
|
||||
try {
|
||||
[Net.ServicePointManager]::SecurityProtocol = "Tls12, Tls13"
|
||||
|
||||
$uri = "$($baseUri)/build/builds/$($buildId)?api-version=6.0"
|
||||
$headers = @{
|
||||
Authorization = "Bearer $accessToken"
|
||||
}
|
||||
|
||||
return Invoke-RestMethod -Method Get -Uri $uri -Headers $headers -UseBasicParsing
|
||||
}
|
||||
catch {
|
||||
Write-Host -ForeGroundColor Red 'Unhandled exception occurred during agent fetch!'
|
||||
Write-Host -ForegroundColor Red $_.Exception.Message
|
||||
throw
|
||||
}
|
||||
}
|
||||
|
||||
Function Get-AzureDevopsAgent() {
|
||||
param(
|
||||
[Parameter(Mandatory = $true)] [string]$baseUri,
|
||||
[Parameter(Mandatory = $true)] [string]$accessToken,
|
||||
[Parameter(Mandatory = $true)] [int]$poolId,
|
||||
[Parameter(Mandatory = $true)] [int]$agentId
|
||||
[Parameter(Mandatory = $true)] [int]$agentId,
|
||||
[Parameter(Mandatory = $true)] [string]$agentName
|
||||
)
|
||||
|
||||
|
||||
try {
|
||||
|
||||
[Net.ServicePointManager]::SecurityProtocol = "Tls12, Tls13"
|
||||
|
||||
$uri = "$($baseUri)/distributedtask/pools/$($poolId)/agents/$($agentId)?api-version=6.0&includeCapabilities=true"
|
||||
|
||||
$headers = @{
|
||||
Authorization = "Bearer $accessToken"
|
||||
}
|
||||
|
||||
return Invoke-RestMethod -Method Get -Uri $uri -Headers $headers -UseBasicParsing
|
||||
|
||||
$uri = "$($baseUri)/distributedtask/pools?api-version=6.0"
|
||||
$responsePools = Invoke-RestMethod -Method Get -Uri $uri -Headers $headers -UseBasicParsing
|
||||
|
||||
foreach ($pool in $responsePools.Value) {
|
||||
|
||||
$uri = "$($baseUri)/distributedtask/pools/$($pool.Id)/agents?api-version=6.0&includeCapabilities=true"
|
||||
$responseAgents = Invoke-RestMethod -Method Get -Uri $uri -Headers $headers -UseBasicParsing
|
||||
|
||||
$agents = $responseAgents.Value.Where({$_.id -eq $agentId -and $_.name -eq $agentName})
|
||||
if (!($agents) -or $agents.Count -eq 0) {
|
||||
continue
|
||||
}
|
||||
|
||||
if ($agents.Count -gt 1) {
|
||||
throw "Multiple agents ($($agents.Count)) found with id: $agentId and name: $agentName"
|
||||
}
|
||||
|
||||
return $agents.Item(0)
|
||||
}
|
||||
|
||||
return $null
|
||||
}
|
||||
catch {
|
||||
|
||||
Write-Host -ForeGroundColor Red 'Unhandled exception occurred during agent fetch!'
|
||||
Write-Host -ForegroundColor Red $_.Exception.Message
|
||||
throw
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Function Output-AgentCapabilities() {
|
||||
param(
|
||||
[Parameter(Mandatory = $true)] [PSCustomObject]$capabilities,
|
||||
[Parameter(Mandatory = $true)] [string]$capabilityType
|
||||
)
|
||||
|
||||
|
||||
foreach ($capability in $capabilities.PSObject.Properties) {
|
||||
$envName = "AgentCapabilities.$($capabilityType).$($capability.Name)".Replace('_', '.')
|
||||
$envValue = $($capability.Value)
|
||||
|
||||
[System.Environment]::SetEnvironmentVariable($envName, $envValue)
|
||||
[System.Environment]::SetEnvironmentVariable($envName, $($capability.Value))
|
||||
}
|
||||
}
|
||||
|
||||
[int]$BuildId = $(Build.BuildId)
|
||||
|
||||
[int]$AgentId = $(Agent.Id)
|
||||
Write-Host "BuildId = $BuildId; AgentId = $AgentId"
|
||||
|
||||
$BuildData = Get-AzureDevopsBuild -baseUri "$(System.CollectionUri)$(System.TeamProject)/_apis" -accessToken $(System.AccessToken) -buildId $BuildId
|
||||
Write-Host $BuildData
|
||||
[string]$AgentName = $(Agent.Name)
|
||||
Write-Host "AgentId = $AgentId; AgentName = $AgentName"
|
||||
|
||||
[int]$PoolId = $BuildData.queue.pool.id
|
||||
Write-Host "PoolId = $PoolId"
|
||||
|
||||
$AgentData = Get-AzureDevopsAgent -baseUri "$(System.CollectionUri)_apis" -accessToken $(System.AccessToken) -poolId $PoolId -agentId $AgentId
|
||||
Write-Host $AgentData
|
||||
|
||||
Output-AgentCapabilities -capabilities $AgentData.systemCapabilities -capabilityType 'System'
|
||||
Output-AgentCapabilities -capabilities $AgentData.userCapabilities -capabilityType 'User'
|
||||
$AgentData = Get-AzureDevopsAgent -baseUri "$(System.CollectionUri)_apis" -accessToken $(System.AccessToken) -agentId $AgentId -agentName $AgentName
|
||||
if ($AgentData) {
|
||||
Output-AgentCapabilities -capabilities $AgentData.systemCapabilities -capabilityType 'System'
|
||||
Output-AgentCapabilities -capabilities $AgentData.userCapabilities -capabilityType 'User'
|
||||
}
|
||||
pwsh: true
|
||||
|
||||
- task: PowerShell@2
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue