简体   繁体   English

Azure Devops Powershell 任务:生成变量的编程访问

[英]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.

相关问题 如何从 Powershell 脚本文件访问 Azure DevOps 预定义变量 - How to access Azure DevOps Predefined variables from Powershell script file 是否可以在 Azure DevOps 的 Azure Powershell 任务中设置变量并将它们传递给另一个任务? - Is it possible to set variables in the Azure Powershell task in Azure DevOps and pass them to another task? Azure DevOps-自定义任务-具有Azure身份验证的PowerShell - Azure DevOps - Custom Task - PowerShell with Azure Authentification Azure powershell 任务中的 AzureRM 命令:Azure DevOps - AzureRM commands in Azure powershell Task: Azure DevOps PowerShell任务脚本路径Azure DevOps发布 - Script path of PowerShell task Azure DevOps release 无法在 Azure DevOPS 中资源组部署任务的覆盖参数中使用来自 PowerShell 脚本的输出变量 - Unable to use output variables from a PowerShell script in the Override Parameters of a Resource Group deployment task in Azure DevOPS 在 Azure DevOps 管道中,在执行 az login 时使用 powershell 任务中的变量会导致 ArgumentParseError - In Azure DevOps pipelines, using variables in the powershell task results in ArgumentParseError when doing az login 如何在 Azure DevOps Azure Powershell 任务中启用 PowerShell 交互模式? - How to enable PowerShell Interactive mode in Azure DevOps Azure Powershell Task? 如何在 Azure devops Powershell@2 任务中的构建变量上编写 foreach 循环? - How to write a foreach loop on build variable in Azure devops Powershell@2 task? 在 Azure powershell 任务中添加/获取 Azure Keyvault 的秘密 - Add/get secret to Azure Keyvault with Azure powershell task in Azure devops
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM