【发布时间】:2022-11-04 04:12:49
【问题描述】:
我有一个 azure devops 管道,我想将保存 json 的变量的内容写入文本文件。
以下是管道中的两个任务:
- task: CmdLine@2
displayName: 'echo swagger content'
inputs:
script: |
echo "print value of swaggerContent output variable set in get-swagger-from-azure.ps1"
echo $(swaggerContent)
- task: PowerShell@2
displayName: 'write swagger content to file'
inputs:
targetType: 'inline'
script: $env:swaggerContent | Out-File "$(Pipeline.Workspace)/swagger-content.json"'
命令行任务处理并输出 json,如下所示:
但是,PowerShell 任务给出以下错误:
在 D:\a_temp\05c70744-c4cc-4322-99a0-98f55e41fbba.ps1:7 char:1
- } 其他 {
- ~ 表达式或语句中出现意外标记“}”。
- CategoryInfo : ParserError: (:) [], ParseException
- FullyQualifiedErrorId:UnexpectedToken
有人看到我做错了什么吗?
【问题讨论】:
-
如果如你所说,内容已经保存 json 的变量,那么为什么在你的脚本中使用
ConvertTo-Json? -
嗨 Theo,那是我在猜测解决方案!没有 ConvertTo-Json 我得到了同样的错误
标签: json powershell azure-devops