小编Rya*_*ey4的帖子

不能使用非字符串的 TFS/VSTS 自定义变量

我一直在使用 TFS 从 PowerShell 创建一些发布变量。然后,我可以在 TFS 中的后续任务中使用“$Env:Server”来引用此输出,这看起来很棒!例如:

任务 1 返回服务器名称,然后创建 TFS 变量:

Write-Host "##vso[task.setvariable variable=Server]"MySevrer
Run Code Online (Sandbox Code Playgroud)

任务 2 使用此信息:

Write-Output $env:Server
MyServer
Run Code Online (Sandbox Code Playgroud)

当以其他格式(如数组或哈希表)输出某些内容时,这不起作用。创建的变量只是字符串,正如文档中使用“Write-Host”所述的那样。

任务1返回:

##vso[task.setvariable variable=Server] System.Collections.DictionaryEntry
Run Code Online (Sandbox Code Playgroud)

任务2不能使用这个:

Write-Output $env:Server    
System.Collections.DictionaryEntry
Run Code Online (Sandbox Code Playgroud)

创建的输出

我尝试将其输出为数组格式的字符串,例如:

[String]$Server = '@{MyServer=@("192.168.0.1")}'
Write-Host "##vso[task.setvariable variable=Server]"$Server
Run Code Online (Sandbox Code Playgroud)

当我提到这一点时,我尝试在 PowerShell 中将其转换回数组,但是,我在脚本中执行此操作时遇到了问题,因为它将将该字符串视为单个数组对象。(不是有值的数组)

有谁知道是否可以根据 Powershell 任务输出的信息来解析 Team Service 的任务/任务任务组之间的哈希表或数组?

我目前已经通过编写包装器/编排函数来解决这个问题,但这对我们来说不是理想的方法。我们目前的版本是 15.117.26714.0,但我在新版本中看不到任何内容。

variables powershell tfs task azure-devops

3
推荐指数
1
解决办法
6819
查看次数

标签 统计

azure-devops ×1

powershell ×1

task ×1

tfs ×1

variables ×1