<p>I have declared the following Variable group in Azure DevOps.</p>

<pre><code>KUBERNETES_CLUSTER = myAksCluster
RESOURCE_GROUP = myResourceGroup
</code></pre>

<p><a href="https://i.stack.imgur.com/KHMWp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KHMWp.png" alt="enter image description here"></a></p>

<p>In the Release pipeline process, I want to create a Public Static IP address in order to assigned to some application in <code>myAksCluster</code>.</p>

<p>Via Azure cli commands I am creating the Static IP address of this way via <strong>az cli bash small script</strong>. We can assume here that I already have created the kubernetes cluster</p>

<pre><code>#!/usr/bin/env bash

KUBERNETES_CLUSTER=myAksCluster
RESOURCE_GROUP=myResourceGroup

# Getting the name of the node resource group. -o tsv is to get the value without " "
NODE_RESOURCE_GROUP=$(az aks show --resource-group $RESOURCE_GROUP --name $KUBERNETES_CLUSTER --query nodeResourceGroup -o tsv)
echo "Node Resource Group:" $NODE_RESOURCE_GROUP

# Creating Public Static IP
PUBLIC_IP_NAME=DevelopmentStaticIp
az network public-ip create --resource-group $NODE_RESOURCE_GROUP --name $PUBLIC_IP_NAME --allocation-method static

# Query the ip
PUBLIC_IP_ADDRESS=$(az network public-ip list --resource-group $NODE_RESOURCE_GROUP --query [1].ipAddress --output tsv)
# Output 
# I want to use the value of PUBLIC_IP_ADDRESS variable in Azure DevOps variable  groups of the release pipeline

</code></pre>

<p>If I execute <code>az network public-ip list ...</code> command I get my public Ip address.</p>

<pre><code>⟩ az network public-ip list --resource-group $NODE_RESOURCE_GROUP --query [1].ipAddress -o tsv
10.x.x.x
</code></pre>

<p>I want to use that <code>PUBLIC_IP_ADDRESS</code> value to assign it to a new Azure DevOps variable groups in my release, but doing all this process <strong>from a CLI task or Azure Cli task like part of the release pipeline process.</strong></p>

<p>The idea is when my previous <strong>az cli bash small script</strong> to be executed in the release pipeline, I have a new variable in my ReleaseDev azure variable groups of this way:</p>

<p><a href="https://i.stack.imgur.com/Dfiq0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Dfiq0.png" alt="enter image description here"></a></p>

<p>And after that, I can use <code>PUBLIC_STATIC_IP_ADDRESS</code> which will be an azure devops variable like arguments to the application which will use that IP value inside my kubernetes cluster.</p>

<p>I have been checking some information and maybe I could create an Azure CLI task in my release pipeline to execute the <strong>az cli bash small script</strong> which is creating the public static ip address of this way:
<a href="https://i.stack.imgur.com/187Po.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/187Po.png" alt="enter image description here"></a></p>

<p>But is finally at the end when I get the public ip address value, that I don't know how to create from this Azure CLI task (my script) the variable <code>PUBLIC_STATIC_IP_ADDRESS</code> with its respective value that I got here.</p>

<p>Can I use an Azure CLI task from the release pipeline to get this small workflow? I have been checking somethings like <a href="https://github.com/Microsoft/azure-pipelines-tasks/issues/9416#issuecomment-470791784" rel="nofollow noreferrer">this recommendation</a> 
but is not clear for me</p>

<p>how to create an Az variable group with some value passed from my release pipeline?
Is Azure CLI release pipeline task, the proper task for do that?</p>

<p><strong>UPDATE</strong></p>

<p>I am following the approach suugested by <strong>Lu Mike</strong>, so I have created a Powershell task and executing the following script in Inline type/mode:</p>

<pre><code># Connect-AzAccount
Install-Module -Name Az -AllowClobber -Force 

@{KUBERNETES_CLUSTER = "$KUBERNETES_CLUSTER"}
@{RESOURCE_GROUP = "$RESOURCE_GROUP"}

@{NODE_RESOURCE_GROUP="$(az aks show --resource-group $RESOURCE_GROUP --name $KUBERNETES_CLUSTER --query nodeResourceGroup -o tsv)"}
# echo "Node Resource Group:" $NODE_RESOURCE_GROUP

@{PUBLIC_IP_NAME="Zcrm365DevelopmentStaticIpAddress"}
az network public-ip create --resource-group $NODE_RESOURCE_GROUP --name $PUBLIC_IP_NAME --allocation-method static

@{PUBLIC_IP_ADDRESS="$(az network public-ip list --resource-group $NODE_RESOURCE_GROUP --query [1].ipAddress --output tsv)"}
echo "##vso[task.setvaraible variable=ipAddress;]%PUBLIC_IP_ADDRESS%"

$orgUrl="https://dev.azure.com/my-org/"

$projectName = "ZCRM365"

##########################################################################
$personalToken = $PAT # "&lt;your PAT&gt;" 
# I am creating a varaible environment inside the power shell task and reference it here.
##########################################################################

$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($personalToken)"))
$header = @{authorization = "Basic $token"}

$projectsUrl = "$($orgUrl)/$($projectName)/_apis/distributedtask/variablegroups/1?api-version=5.0-preview.1"

$requestBody = @{
    "variables" = @{
        "PUBLIC_STATIC_IP_ADDRESS" = @{
            "value" = "$PUBLIC_IP_ADDRESS"
        }
    }
    "@type" = "Vsts"
    "name" = "ReleaseVariablesDev"
    "description" = "Updated variable group"
} | ConvertTo-Json

Invoke-RestMethod -Uri $projectsUrl -Method Put -ContentType "application/json" -Headers $header -Body $requestBody
Invoke-RestMethod -Uri $projectsUrl -Method Put -ContentType "application/json" -Headers $header -Body $requestBody
</code></pre>

<hr>

<p><strong>IMPORTANT</strong></p>

<p>As you can see, in this process I am mixing <code>az cli</code> commands and powershell language in this task. I am not sure if it is good. 
By the way I am using a Linux Agent.</p>

<p>I had to include <code>-Force</code> flag to the <code>Install-Module -Name Az -AllowClobber -Force</code> command to install azure powershell module </p>

<hr>

<p>My output is the following:</p>

<pre><code>2019-07-19T06:01:29.6372873Z Name                           Value
2019-07-19T06:01:29.6373433Z ----                           -----
2019-07-19T06:01:29.6373706Z KUBERNETES_CLUSTER             
2019-07-19T06:01:29.6373856Z RESOURCE_GROUP                 
2019-07-19T06:01:38.0177665Z ERROR: az aks show: error: argument --resource-group/-g: expected one argument
2019-07-19T06:01:38.0469751Z usage: az aks show [-h] [--verbose] [--debug]
2019-07-19T06:01:38.0470669Z                    [--output {json,jsonc,table,tsv,yaml,none}]
2019-07-19T06:01:38.0471442Z                    [--query JMESPATH] --resource-group RESOURCE_GROUP_NAME
2019-07-19T06:01:38.0472050Z                    --name NAME [--subscription _SUBSCRIPTION]
2019-07-19T06:01:38.1381959Z NODE_RESOURCE_GROUP            
2019-07-19T06:01:38.1382691Z PUBLIC_IP_NAME                 Zcrm365DevelopmentStaticIpAddress
2019-07-19T06:01:39.5094672Z ERROR: az network public-ip create: error: argument --resource-group/-g: expected one argument
2019-07-19T06:01:39.5231190Z usage: az network public-ip create [-h] [--verbose] [--debug]
2019-07-19T06:01:39.5232152Z                                    [--output {json,jsonc,table,tsv,yaml,none}]
2019-07-19T06:01:39.5232671Z                                    [--query JMESPATH] --resource-group
2019-07-19T06:01:39.5233234Z                                    RESOURCE_GROUP_NAME --name NAME
2019-07-19T06:01:39.5233957Z                                    [--location LOCATION]
2019-07-19T06:01:39.5234866Z                                    [--tags [TAGS [TAGS ...]]]
2019-07-19T06:01:39.5235731Z                                    [--allocation-method {Static,Dynamic}]
2019-07-19T06:01:39.5236428Z                                    [--dns-name DNS_NAME]
2019-07-19T06:01:39.5236795Z                                    [--idle-timeout IDLE_TIMEOUT]
2019-07-19T06:01:39.5237070Z                                    [--reverse-fqdn REVERSE_FQDN]
2019-07-19T06:01:39.5240483Z                                    [--version {IPv4,IPv6}]
2019-07-19T06:01:39.5250084Z                                    [--sku {Basic,Standard}] [--zone {1,2,3}]
2019-07-19T06:01:39.5250439Z                                    [--ip-tags IP_TAGS [IP_TAGS ...]]
2019-07-19T06:01:39.5251048Z                                    [--public-ip-prefix PUBLIC_IP_PREFIX]
2019-07-19T06:01:39.5251594Z                                    [--subscription _SUBSCRIPTION]
2019-07-19T06:01:40.4262896Z ERROR: az network public-ip list: error: argument --resource-group/-g: expected one argument
2019-07-19T06:01:40.4381683Z usage: az network public-ip list [-h] [--verbose] [--debug]
2019-07-19T06:01:40.4382086Z                                  [--output {json,jsonc,table,tsv,yaml,none}]
2019-07-19T06:01:40.4382346Z                                  [--query JMESPATH]
2019-07-19T06:01:40.4382668Z                                  [--resource-group RESOURCE_GROUP_NAME]
2019-07-19T06:01:40.4382931Z                                  [--subscription _SUBSCRIPTION]
2019-07-19T06:01:40.5103276Z PUBLIC_IP_ADDRESS              
2019-07-19T06:01:40.5133644Z ##[error]Unable to process command '##vso[task.setvaraible variable=ipAddress;]%PUBLIC_IP_ADDRESS%' successfully. Please reference documentation (http://go.microsoft.com/fwlink/?LinkId=817296)
2019-07-19T06:01:40.5147351Z ##[error]##vso[task.setvaraible] is not a recognized command for Task command extension. Please reference documentation (http://go.microsoft.com/fwlink/?LinkId=817296)
</code></pre>

<p>And maybe that is why I have some problem to execute <code>az</code> commands</p>

<p>Power shell and its respective azure task are new for me, and I am not sure about how can I get along of this process.</p>

bgarcial
<p>You can use the Rest API as <strong>Lu Mike</strong> mentioned to update the variable group, or you can install the <a href="https://marketplace.visualstudio.com/items?itemName=Lanalua.lanalua-variableupdater" rel="nofollow noreferrer">Shared variable updater</a> extension that do it for you.</p>

<p>But the important thing is, you need to set a variable in the Azure CLI task that you can use it in the second task (either it's Rest API task or the Shared variable updater task). so you need to add this line to your script:</p>

<pre><code>echo "##vso[task.setvaraible variable=ipAddress;]%PUBLIC_IP_ADDRESS%"
</code></pre>

<p>Now in the next tasks you can use the variable <code>$(ipAddress)</code> that contains the ip value:</p>

<p><a href="https://i.stack.imgur.com/1CPeu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1CPeu.png" alt="enter image description here"></a></p>
