powershell - 如何在作为 VSTS 构建/发布的一部分运行的 PowerShell 脚本中检索变量?

标签 powershell azure-devops

当我运行 powershell 脚本时,我在 VSTS 中遇到错误。

我在我的代理上安装了 powershell。但我仍然收到此错误:

The term 'Get-VstsInput' is not recognized as the name of a cmdlet, function, script file, or operable program.



我错过了什么。

最佳答案

您可以使用 $env:VariableName 访问 PowerShell 脚本中的变量.唯一的异常(exception)是 secret 变量。这些必须通过 param 显式传递到脚本中堵塞。

例如,如果您有一个名为 $(Foo) 的变量,您可以在 PowerShell 脚本中访问它作为 $env:Foo .如果变量名中有句点,则用下划线替换它们。所以$(Foo.Bar)变成 $env:Foo_Bar .

这也不适用于目标计算机上的 PowerShell。如果您通过该任务在远程计算机上运行 PowerShell 脚本,则必须将任何变量作为参数传递,因为构建代理的环境变量未填充到目标计算机上。

除非您正在编写自定义任务,否则无需使用 VSTS SDK。

关于powershell - 如何在作为 VSTS 构建/发布的一部分运行的 PowerShell 脚本中检索变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51654974/

相关文章:

azure - 从变量中读取 Azure Key Vault 任务中的 secret 变量

powershell - 使用 powershell 安装最新的 chrome

powershell - 函数完成后 Import-PsSession 不可用

node.js - npm 错误! azure devops 中的代码 ELIFECYCLE 无法使其运行

git - 如何在 VSTS 中 CI 构建分支

azure - 使用 ADF 将文件夹从具有 2 级子文件夹的 Azure 容器移动到与子文件夹同名的容器级

azure - 获取 VSTS 发布管道中使用的任务组版本

windows - 使用所有参数从批处理文件调用 PowerShell 脚本

powershell - 如何写回使用通配符路径读取的同一文件?

asp.net - 将文件表单 powershell 上传到 asp.net