如何在 PowerShell 构建步骤中查询 TFS 构建定义自定义变量

How can I query a TFS Build Definition custom defined variable within a PowerShell Build Step

在我的 TFS 构建定义中,我想在“变量”选项卡中创建一个自定义变量。这个变量我想命名为 MyVariable.

在我的构建定义中,我有一个 PowerShell 脚本步骤。 在这个powershell脚本中(PS1)我想查询变量的值。

我该怎么做?

我尝试了以下方法,但它们不起作用:

Write-Host "MyVariable: $Env:MyVariable"
Write-Host "MyVariable: $MyVariable

使用“参数”部分将变量传递到您的 Powershell 脚本任务中。如果您的变量名为 MyVariable,则应按以下格式传递它:$(MyVariable) 在您的 Powershell 脚本中,您可以访问变量的值,因为您将它作为参数传递。

Manu是对的,PowerShell脚本格式不对

请尝试:

Write-Host "MyVariable:" $Env:MyVariable