You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular部署:PowerShell递归复制脚本在Linux构建代理报错求助

问题描述

部署Angular应用时,用PowerShell脚本复制dist文件,Windows本地运行正常,但在Azure DevOps的Linux构建代理执行时报错:

  • CI执行命令:pwsh -NoProfile -File ./scripts/copy.ps1 -source ./build/en/* -destination ./build
  • 报错信息:copy.ps1: A positional parameter cannot be found that accepts argument './build/en/GVS_Icons.eot'
  • 涉及的脚本内容:
param(
    [Parameter(Mandatory = $true)][string]$source,
    [Parameter(Mandatory = $true)][string]$destination
)

Copy-Item -Path $source -Destination $destination -Force -Recurse
报错原因
  • Linux Shell抢先解析通配符:在Windows环境下,./build/en/*通配符由PowerShell自行解析处理;但在Linux代理环境中,执行命令时是Linux的Shell(如bash)先将通配符展开为./build/en目录下的所有文件路径,这些展开后的路径会被当作多个位置参数传递给脚本。而脚本仅定义了-source和-destination两个参数,多余的文件路径就成了无法识别的位置参数,直接触发报错。
  • 参数类型适配问题:脚本将$source定义为[string]单字符串类型,即便由PowerShell解析通配符,多个匹配项也会生成字符串数组,与定义的类型不匹配,但这并非本次报错的直接原因,核心矛盾还是Linux Shell提前完成了通配符展开。

内容的提问来源于stack exchange,提问作者lekso

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 08:29:53