Functions/AzDevOps/Add-CdsDevOpsVariableGroup.ps1

<#
    .SYNOPSIS
    Push CDS Instance data to a Az DevOps variable group.
#>

function Add-CdsDevOpsVariableGroup {
    [CmdletBinding()]
    param
    (        
        [Parameter(Mandatory = $false, ValueFromPipeline)]
        $CdsInstance
    )
    begin {   
        $StopWatch = [System.Diagnostics.Stopwatch]::StartNew(); 
        Trace-CdsFunction -Name $MyInvocation.MyCommand.Name -Stage Start -Parameters ($MyInvocation.MyCommand.Parameters);
    }    
    process {
        $body = '{
            "variables": {
                "ConnectionString": {
                  "value": "[#ConnectionString#]"
                }
            },
            "type": "Vsts",
            "name": "[#Name#]",
            "description": ""
        }'
;
        $body = $body.Replace("[#ConnectionString#]", $CdsInstance.ConnectionString);
        $body = $body.Replace("[#Name#]", $CdsInstance.Name);

        Invoke-CdsDevOpsApi -RelativeApiUrl "/distributedtask/variablegroups" -Method POST -Body $body | Out-Null;
    }
    end {
        $StopWatch.Stop();
        Trace-CdsFunction -Name $MyInvocation.MyCommand.Name -Stage Stop -StopWatch $StopWatch;
    }    
}

Export-ModuleMember -Function Add-CdsDevOpsVariableGroup -Alias *;