[英]Azure Devops Powershell task: Programmatic Access of Build Variables
Hi I want to know if I can programatically access my release variables in the powershell release task.嗨,我想知道我是否可以在 powershell 发布任务中以编程方式访问我的发布变量。 My use case is this: I want to create a generic powershell script that can be used to deploy to multiple environments.
我的用例是这样的:我想创建一个可用于部署到多个环境的通用 powershell 脚本。 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.
我想在 powershell 任务上设置一个环境变量,该变量将指定 env=dev 或 test 或 prod 等。所以我希望 powershell 脚本根据环境变量动态访问适当的构建变量(不创建大量的 switch 语句) . 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.目前 $apiUrl 能够很好地检索发布变量,但我不想在参数名称中硬编码“dev”。
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?所以我想知道这是一种从我的 powershell 任务中以编程方式访问这些发布变量的方法吗?
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.在您的环境中使用相同的变量名称,并在不同的范围内定义不同的值。 ie the DEV environment has a
Kudu.Url
variable set to the value for the dev environment.即 DEV 环境有一个
Kudu.Url
变量设置为 dev 环境的值。 The QA environment has a Kudu.Url
set to the value for the QA environment. QA 环境有一个
Kudu.Url
设置为 QA 环境的值。 And so on.等等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.