PowerShell脚本本地正常,Azure发布管道抛出ReadAllText异常
Azure Release Pipeline中操作Zip内JSON文件的问题
我需要在Azure Release Pipeline中完成以下操作:
- 打开.zip文件
- 找到指定名称的JSON文件
- 编辑并保存该文件
- 关闭.zip文件
该脚本在本地运行正常,但添加PowerShell任务(支持在Linux、macOS或Windows上运行)到Azure发布管道后,抛出异常:
Exception calling "ReadAllText" with "2" argument(s): "Could not find file 'C:\azagent\A1\_work\r17\a\appsettings.Production.json'." At C:\azagent\A1\_work\_temp\75ed88f3-4260-42d8-afba-43d0aa0f6a93.ps1:40 char:1+ $JsonData = [IO.File]::ReadAllText($configFile, [Text.Encoding]::GetEncoding( 125 ...
问题出在以下代码行:
$JsonData = [IO.File]::ReadAllText($configFile, [Text.Encoding]::GetEncoding(1252)) | ConvertFrom-Json
我找不到其他读取Zip内文件内容的方法,比如Get-Content需要实际路径。原以为是[IO.File]::ReadAllText的参数问题,但本地运行正常。
补充说明:已找到本地正常的原因——使用WinRar打开文件时会将其临时解压到temp文件夹,但尚未找到Azure发布管道中的解决办法,推测可能与PowerShell版本有关。
内容的提问来源于stack exchange,提问作者Kadaj
相关产品推荐
相关产品推荐

