在 Azure Devops 或 TFS 中是否可以传递在管道环境中可变的 PowerShell 参数?

In Azure Devops or TFS is it possible to pass a PowerShell argument that is variable on the pipeline environment?

我正在尝试创建一个可以在构建和发布管道之间互换使用的任务组。

但是,我在将其中一个参数传递给我的 Powershell 任务组时遇到问题。

这是因为我尝试传递的参数数据在构建环境中不存在。

- envName "$(Release.EnvironmentName)"

例如,如果此任务组在构建环境中执行,我是否可以设置发送不同变量的逻辑?

有没有办法让我仅在存在此参数时通过它?或者传递这个论点或不同的论点?

谢谢!

In Azure Devops or TFS is it possible to pass a PowerShell argument that is variable on the pipeline environment?

恐怕没有这样的方法可以直接传递在管道环境中可变的 PowerShell 参数。

但作为解决方法,您可以在 Powershell 任务组中添加另一个 powershell 任务以根据管道环境设置变量,例如:

Write-Host "Current Release Name is $Env:Release_EnvironmentName"

$ReleaseName= $Env:Release_EnvironmentName

Write-Host "Current Environment Release Name is $ReleaseName"

if ($ReleaseName-eq "")
{
  Write-Host ("##vso[task.setvariable variable=envName]TestValue1")
}
else
{
  Write-Host ("##vso[task.setvariable variable=envName]TestValue2")
}

envName将根据$Env:Release_EnvironmentName的值设置不同的值,我们可以在Powershell任务组的下一个Powershell任务中使用它。

查看 build/release 期间的 Logging Command 了解更多详情。

希望对您有所帮助。