Vsts 将变量作为对象数组传递

Vsts pass variable as array of objects

我正在尝试将变量作为对象数组传递给发布管道。 我的目标是 appsettings.json 类似

"myArrayObject": [
      {
        "host": "localhost:2948",
        "protocol": "http"
      }
    ]

在变量选项卡中,我创建了名为 myArrayObject 的变量并分配给它

[{'host':'someUrl','protocol':'https'},{'host':'localhost:44394','protocol':'https'}]

不知何故变量未被发布修改,所以我将这个脚本添加到管道

powershell -command "&{
 $json = Get-Content '.\appsettings.json' -raw | ConvertFrom-Json;
 $json.myArrayObject = '$(myArrayObject)';
 $json | ConvertTo-Json -Depth 32 | Set-Content '.\appsettings.json'; 
 }"

但是我得到了错误

Missing type name after '['.
At line:1 char:129
+ ... llowedUris = [{'host':'someUrl','protoc ...
+                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unexpected token ':'someUrl'' in expression or 
statement.
At line:1 char:169
+ ... lowedUris = [{'host':'someUrl','protoco ...

有什么办法可以实现吗?将对象数组作为变量传递?

我也试过这个方法:

powershell -command "&{
 $json = Get-Content '.\appsettings.json' -raw | ConvertFrom-Json;
 $json.myArrayObject = '[{"host":"someUrl","protocol":"https"},{"host":"localhost:44394","protocol":"https"}]';
 $json | ConvertTo-Json -Depth 32 | Set-Content '.\appsettings.json'; 
 }"

但最后我得到了:

"myArrayObject" : "[{host:someUrl,protocol:https},{host:localhost:44394,protocol:https}]"

这是解决方案:

powershell -command "&{
    $json = Get-Content '.\appsettings.json' -raw | ConvertFrom-Json;
     $data = '$(additionalAllowedUris)' | ConvertFrom-Json;
     $json.additionalAllowedUris= $data.SyncRoot;
     $json | ConvertTo-Json -Depth 32 | Set-Content '.\appsettings.json';
    }"

[{ \"host\" : \"someUrl\",\"protocol\" : \"https\"},{ \"host\":\"localhost:44394\",\"protocol\" : \"https\"},{ \"host\":\"someUrl2\",\"protocol\" : \"https\"}]