How can i pass a variable between tasks in Azure Devops/VSTS

蓝咒 提交于 2021-02-10 15:11:31

问题


For Task 1 I have a CLI task which simply gets the subnet name and subnet ref as below

$subnetname1 = az network vnet subnet list --resource-group vnetrg01 --vnet-name vnet01 --query "[].name" -o tsv $subnetref1 = az network vnet subnet list --resource-group vnetrg01 --vnet-name vnet01 --query "[].id" -o tsv

For task 2 I want to deploy an arm template which will use parameters from the pipleine variables in Azure Devops So for example the result of $subnetref1 in Task 1 above needs to populate the pipleline variable for subnetref (which is setup as a variable in the pipleine) which will then be passed to the arm template override parameters

cant seem to get this working


回答1:


You can do it with Powershell command,

In the first PowerShell task set the variable as environment variable:

$subnetname1 =  az network vnet subnet list --resource-group vnetrg01 --vnet-name vnet01 --query "[].name" -o tsv 
Write-Host $subnetname1
Write-Host ("##vso[task.setvariable variable=subnetname1;]$subnetname1")

In the second task read the variable in this way:

$subnetname1 =  $env:subnetname1
Write-Host $subnetname1


来源:https://stackoverflow.com/questions/62263609/how-can-i-pass-a-variable-between-tasks-in-azure-devops-vsts

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!