0

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 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

You are 100% right here. Didn't know that was a thing but completely the right way to address this problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.