mirror of
https://github.com/tribufu/ServerManagers
synced 2026-05-06 15:17:34 +00:00
Merge branch 'source' of https://github.com/Bletch1971/ServerManagers into source
This commit is contained in:
commit
dcad782ef4
1 changed files with 5 additions and 74 deletions
|
|
@ -37,89 +37,20 @@ stages:
|
|||
steps:
|
||||
- task: PowerShell@2
|
||||
displayName: Create AgentCapabilities Environment Variables
|
||||
enabled: false
|
||||
enabled: true
|
||||
env:
|
||||
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
|
||||
inputs:
|
||||
targetType: 'inline'
|
||||
script: |
|
||||
Function Get-AzureDevopsAgent() {
|
||||
param(
|
||||
[Parameter(Mandatory = $true)] [string]$baseUri,
|
||||
[Parameter(Mandatory = $true)] [string]$accessToken,
|
||||
[Parameter(Mandatory = $true)] [int]$agentId,
|
||||
[Parameter(Mandatory = $true)] [string]$agentName
|
||||
)
|
||||
|
||||
try {
|
||||
[Net.ServicePointManager]::SecurityProtocol = "Tls12, Tls13"
|
||||
|
||||
$headers = @{
|
||||
Authorization = "Bearer $accessToken"
|
||||
}
|
||||
|
||||
$uri = "$($baseUri)/distributedtask/pools?api-version=6.0"
|
||||
$responsePools = Invoke-RestMethod -Method Get -Uri $uri -Headers $headers -UseBasicParsing
|
||||
Write-Host $responsePools
|
||||
|
||||
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
|
||||
Write-Host $responseAgents
|
||||
|
||||
$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)
|
||||
}
|
||||
|
||||
Write-Host -ForeGroundColor Yellow 'Agent NOT found'
|
||||
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
|
||||
)
|
||||
|
||||
[int]$count = 0
|
||||
foreach ($capability in $capabilities.PSObject.Properties) {
|
||||
$envName = "AgentCapabilities.$($capabilityType).$($capability.Name)".Replace('_', '.')
|
||||
[System.Environment]::SetEnvironmentVariable($envName, $($capability.Value))
|
||||
|
||||
$count = $count + 1
|
||||
}
|
||||
|
||||
Write-Host -ForeGroundColor Cyan "Created $count AgentCapabilities.$capabilityType environment variables"
|
||||
}
|
||||
|
||||
$AgentData = Get-AzureDevopsAgent -baseUri "$(System.CollectionUri)_apis" -accessToken $(System.AccessToken) -agentId $(Agent.Id) -agentName $(Agent.Name)
|
||||
if ($AgentData) {
|
||||
Output-AgentCapabilities -capabilities $AgentData.systemCapabilities -capabilityType 'System'
|
||||
Output-AgentCapabilities -capabilities $AgentData.userCapabilities -capabilityType 'User'
|
||||
}
|
||||
targetType: filePath
|
||||
filePath: './.azure/scripts/CreateAgentCapabilitiesEnvironmentVariables.ps1'
|
||||
arguments: "-CollectionUri '$(System.CollectionUri)' -AgentId '$(Agent.Id)' -AgentName '$(Agent.Name)' -AccessToken '$(System.AccessToken)' -DebugMode $(System.Debug)"
|
||||
pwsh: true
|
||||
|
||||
- task: PowerShell@2
|
||||
displayName: Output Environment Variables
|
||||
condition: contains(variables['system.debug'], 'true')
|
||||
inputs:
|
||||
targetType: 'inline'
|
||||
targetType: inline
|
||||
script: '(gci env:*).GetEnumerator() | Sort-Object Name | Out-String'
|
||||
pwsh: true
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue