2

I'm trying to accomplish a cascading variable, where when one design time variable is set, it cascades to other variables. Is this possible? I've tried with dot notation, I've tried without dot notation, and I've tried to do it in the task:

Dot Notation Variables

Not Dot Notation

Inside Task

I also tried this task plugin, but my agents are on 2.0 and the task doesn't run.

Variable Toolbox Task

Any ideas?

Answer:

You can override these variables at the environment level. I will have to expand these variables in my script manually and then set them to the resolved values in this script.

KrisSodroski
  • 2,796
  • 3
  • 24
  • 39
  • It works fine for me: `Server: $(Server.$(Environment))`. How do you use `Server` variable? (I used it in argument of PowerShell task) What's the version of the agent version (Hosted agent and private agent (2.120.2) work fine) – starian chen-MSFT Oct 16 '17 at 05:08
  • 1
    Do you solve this issue? – starian chen-MSFT Oct 19 '17 at 01:34
  • @starain-MSFT yes, your answer will actually solve this issue, since I can write a program to pull the VSTS build variables from a script, then expand these variables myself in that script. Thanks for your input. – KrisSodroski Oct 19 '17 at 15:35

2 Answers2

1

Instead of having different variables for each environment, use the same variable but override it at the environment level.

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
1

You can set the variable value through Logging Command during the build:

  1. Add PowerShell task

Script: (Need to use _ instead if the variable contains ., such as Server.Dev=> Server_Dev)

$v= [Environment]::GetEnvironmentVariable("Server_$env:Environment")
Write-Host ("##vso[task.setvariable variable=Server;]$v")
  1. Then the following tasks could use Server variable with corresponding value
starian chen-MSFT
  • 33,174
  • 2
  • 29
  • 53