Set Output Variable in Azure CLI task on VSTS

Refer to this code below:

call {your command}>tmpFile1
set /p myvar= < tmpFile1 
echo "##vso[task.setvariable variable=testvar;]%myvar%"

or

FOR /F "tokens=* USEBACKQ" %%F IN (`{your command}`) DO (
SET var=%%F
)
echo "##vso[task.setvariable variable=testvar;]%var%"

Mechaflash's answer in How to set commands output as a variable in a batch file


If using Azure CLI version 2.*, you can use a powershell command rather than batch script wizardry. Microsoft's documentation found here

For example if you needed access token to update azure database it would look like so:

$token= & az account get-access-token --resource=https://database.windows.net --query accessToken
Write-Output("##vso[task.setvariable variable=sqlToken;]$token")