【发布时间】:2024-01-07 03:29:01
【问题描述】:
我正在尝试将变量作为对象数组传递给释放管道。
目标是在我的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 azure-devops azure-pipelines-release-pipeline azure-artifacts