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
501e2755bb
commit
a67756b645
1 changed files with 5 additions and 74 deletions
|
|
@ -37,89 +37,20 @@ stages:
|
||||||
steps:
|
steps:
|
||||||
- task: PowerShell@2
|
- task: PowerShell@2
|
||||||
displayName: Create AgentCapabilities Environment Variables
|
displayName: Create AgentCapabilities Environment Variables
|
||||||
enabled: false
|
enabled: true
|
||||||
env:
|
env:
|
||||||
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
|
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
|
||||||
inputs:
|
inputs:
|
||||||
targetType: 'inline'
|
targetType: filePath
|
||||||
script: |
|
filePath: './.azure/scripts/CreateAgentCapabilitiesEnvironmentVariables.ps1'
|
||||||
Function Get-AzureDevopsAgent() {
|
arguments: "-CollectionUri '$(System.CollectionUri)' -AgentId '$(Agent.Id)' -AgentName '$(Agent.Name)' -AccessToken '$(System.AccessToken)' -DebugMode $(System.Debug)"
|
||||||
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'
|
|
||||||
}
|
|
||||||
pwsh: true
|
pwsh: true
|
||||||
|
|
||||||
- task: PowerShell@2
|
- task: PowerShell@2
|
||||||
displayName: Output Environment Variables
|
displayName: Output Environment Variables
|
||||||
condition: contains(variables['system.debug'], 'true')
|
condition: contains(variables['system.debug'], 'true')
|
||||||
inputs:
|
inputs:
|
||||||
targetType: 'inline'
|
targetType: inline
|
||||||
script: '(gci env:*).GetEnumerator() | Sort-Object Name | Out-String'
|
script: '(gci env:*).GetEnumerator() | Sort-Object Name | Out-String'
|
||||||
pwsh: true
|
pwsh: true
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue