DistributedTasks/Add-AzureDevOpsDeploymentGroup.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function Add-AzureDevOpsDeploymentGroup {
    param (
        [string]$name,
        [string]$organizationUri,
        [string]$projectName,
        [string]$vstsToken,
        [string]$description = "",
        [string]$poolType = "deployment"
    )
    Process {
        $body     = @{ "name" = $name; "description" = $description; "poolType" = $poolType; } | ConvertTo-Json -Compress
        $headers  = @{ "Authorization" = "Basic $([System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes("vsts:$vstsToken")))"; "Content-Type" = "application/json"; }
        $uri      = "$organizationUri/${projectName}/_apis/distributedtask/deploymentgroups/?api-version=5.1-preview.1"
        
        Write-Host "Add deployment-group $name to '$organizationUri' (project: $($projectName))" -f Gray
        $group = ((Invoke-WebRequest -Method Post -Body $body -uri $uri -Headers $headers -UseBasicParsing).Content | ConvertFrom-Json)
        Write-Host "Deployment-group $($group.name) / pool: $($group.pool.name) to '$organizationUri' (project: $($projectName)) added." -f Gray
        return $group
    }
}
#Set-Alias -Name Add-AzureDevOpsDeploymentGroup -Value Add-DevOpsDeploymentGroup
Export-ModuleMember -Function Add-AzureDevOpsDeploymentGroup #-Alias Add-DevOpsDeploymentGroup