0
votes

Hi I want to know if I can programatically access my release variables in the powershell release task. My use case is this: I want to create a generic powershell script that can be used to deploy to multiple environments. I want to set an environment variable on the powershell task that will specify env=dev or test or prod, etc. So I want the powershell script to dynamically access the appropriate build variables (without creating a massive switch statement) based on the environment variable. I'm able to access the environment variable just fine.

So I have this:

$deployenv = "${Env:kudu.env}"    #(this works just fine)
$apiUrl = '$(dev.kudu.url)'       #(when hard coded like this it works fine)

Currently $apiUrl is able to retrieve the release variable just fine but I don't want to hard code "dev" in the param name.

I've tried a bunch of things like

$apiUrl = variables["$deployenv.kudu.url"]

So I'm wondering is that a way to programatically access these release variables from my powershell task?

1

1 Answers

2
votes

You're trying to implement a solution to the wrong problem. The actual problem is that you're not using variable scopes properly.

Use the same variable names across your environments and define different values at different scopes. i.e. the DEV environment has a Kudu.Url variable set to the value for the dev environment. The QA environment has a Kudu.Url set to the value for the QA environment. And so on.