mirror of
https://github.com/tribufu/ServerManagers
synced 2026-06-01 09:42:39 +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:
|
inputs:
|
||||||
targetType: 'inline'
|
targetType: 'inline'
|
||||||
script: |
|
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() {
|
Function Get-AzureDevopsAgent() {
|
||||||
param(
|
param(
|
||||||
[Parameter(Mandatory = $true)] [string]$baseUri,
|
[Parameter(Mandatory = $true)] [string]$baseUri,
|
||||||
[Parameter(Mandatory = $true)] [string]$accessToken,
|
[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 {
|
try {
|
||||||
|
|
||||||
[Net.ServicePointManager]::SecurityProtocol = "Tls12, Tls13"
|
[Net.ServicePointManager]::SecurityProtocol = "Tls12, Tls13"
|
||||||
|
|
||||||
$uri = "$($baseUri)/distributedtask/pools/$($poolId)/agents/$($agentId)?api-version=6.0&includeCapabilities=true"
|
|
||||||
$headers = @{
|
$headers = @{
|
||||||
Authorization = "Bearer $accessToken"
|
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 {
|
catch {
|
||||||
|
|
||||||
Write-Host -ForeGroundColor Red 'Unhandled exception occurred during agent fetch!'
|
Write-Host -ForeGroundColor Red 'Unhandled exception occurred during agent fetch!'
|
||||||
Write-Host -ForegroundColor Red $_.Exception.Message
|
Write-Host -ForegroundColor Red $_.Exception.Message
|
||||||
throw
|
throw
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Function Output-AgentCapabilities() {
|
Function Output-AgentCapabilities() {
|
||||||
param(
|
param(
|
||||||
[Parameter(Mandatory = $true)] [PSCustomObject]$capabilities,
|
[Parameter(Mandatory = $true)] [PSCustomObject]$capabilities,
|
||||||
[Parameter(Mandatory = $true)] [string]$capabilityType
|
[Parameter(Mandatory = $true)] [string]$capabilityType
|
||||||
)
|
)
|
||||||
|
|
||||||
foreach ($capability in $capabilities.PSObject.Properties) {
|
foreach ($capability in $capabilities.PSObject.Properties) {
|
||||||
$envName = "AgentCapabilities.$($capabilityType).$($capability.Name)".Replace('_', '.')
|
$envName = "AgentCapabilities.$($capabilityType).$($capability.Name)".Replace('_', '.')
|
||||||
$envValue = $($capability.Value)
|
[System.Environment]::SetEnvironmentVariable($envName, $($capability.Value))
|
||||||
|
|
||||||
[System.Environment]::SetEnvironmentVariable($envName, $envValue)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[int]$BuildId = $(Build.BuildId)
|
|
||||||
[int]$AgentId = $(Agent.Id)
|
[int]$AgentId = $(Agent.Id)
|
||||||
Write-Host "BuildId = $BuildId; AgentId = $AgentId"
|
[string]$AgentName = $(Agent.Name)
|
||||||
|
Write-Host "AgentId = $AgentId; AgentName = $AgentName"
|
||||||
$BuildData = Get-AzureDevopsBuild -baseUri "$(System.CollectionUri)$(System.TeamProject)/_apis" -accessToken $(System.AccessToken) -buildId $BuildId
|
|
||||||
Write-Host $BuildData
|
|
||||||
|
|
||||||
[int]$PoolId = $BuildData.queue.pool.id
|
$AgentData = Get-AzureDevopsAgent -baseUri "$(System.CollectionUri)_apis" -accessToken $(System.AccessToken) -agentId $AgentId -agentName $AgentName
|
||||||
Write-Host "PoolId = $PoolId"
|
if ($AgentData) {
|
||||||
|
Output-AgentCapabilities -capabilities $AgentData.systemCapabilities -capabilityType 'System'
|
||||||
$AgentData = Get-AzureDevopsAgent -baseUri "$(System.CollectionUri)_apis" -accessToken $(System.AccessToken) -poolId $PoolId -agentId $AgentId
|
Output-AgentCapabilities -capabilities $AgentData.userCapabilities -capabilityType 'User'
|
||||||
Write-Host $AgentData
|
}
|
||||||
|
|
||||||
Output-AgentCapabilities -capabilities $AgentData.systemCapabilities -capabilityType 'System'
|
|
||||||
Output-AgentCapabilities -capabilities $AgentData.userCapabilities -capabilityType 'User'
|
|
||||||
pwsh: true
|
pwsh: true
|
||||||
|
|
||||||
- task: PowerShell@2
|
- task: PowerShell@2
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue