MethodsAndPractices / vsteam

PowerShell module for accessing Azure DevOps Services and Azure DevOps Server (formerly VSTS or TFS)
https://methodsandpractices.github.io/vsteam-docs/
MIT License
447 stars 155 forks source link

Add support for "elasticPools" #520

Open o-l-a-v opened 1 year ago

o-l-a-v commented 1 year ago

Proposal

Please add support for creating, getting and setting "elasticPools". I want to create a Azure Automation Account runbook that sets minimum amount of VMSS / Azure DevOps self-hosted scale set agents to 1 during work hours, else 0. I planned to use VSTeam module, but don't think you have cmdlets for that yet?

Anyhow, here is a PowerShell example for getting a elasticPool:

# Set PAT
$PAT = [securestring](Read-Host -Prompt 'Paste PAT' -AsSecureString)

# Set TLS version
if ([System.Net.ServicePointManager]::SecurityProtocol.ToString() -ne 'Tls12') {
    [System.Net.ServicePointManager]::SecurityProtocol = 'Tls12'
}

# Get pool
Invoke-RestMethod -Uri 'https://dev.azure.com/<redacted>/_apis/distributedtask/pools/<redacted>?api-version=7.0' -Method 'Get' -Headers @{
    'Authorization' = [string] 'Basic {0}' -f (
        [Convert]::ToBase64String(
            [System.Text.Encoding]::UTF8.GetBytes(
                ':'+[System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($PAT))
            )
        )
    )
}

# Get elasticPool
Invoke-RestMethod -Uri 'https://dev.azure.com/<redacted>/_apis/distributedtask/elasticPools/<redacted>?api-version=7.0' -Method 'Get' -Headers @{
    'Authorization' = [string] 'Basic {0}' -f (
        [Convert]::ToBase64String(
            [System.Text.Encoding]::UTF8.GetBytes(
                ':'+[System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($PAT))
            )
        )
    )
}

And here are some documentation:

Solved Problem

Would help me to scale VMSS ADO agents up and down.

Additional info / code snippets?

No response