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

在Azure DevOps pipeline的codeway.yml中如何用通配符复制带版本的exe文件

问题根因

  • 原有命令末尾多了多余的)符号,直接导致路径识别错误
  • Windows环境下,通配符放在引号包裹的路径字符串中不会被自动解析,无法匹配带版本号的目标文件
  • 如果通配符匹配到多个结果,直接复制到固定文件名会执行失败,需要先确保匹配到唯一的目标exe文件

正确实现方式

方式1:PowerShell任务(Azure DevOps Windows环境推荐使用)

Azure DevOps Windows代理中cp是PowerShell Copy-Item的别名,推荐用以下YAML配置,兼容性更强:

- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
      # 匹配唯一的带版本号的exe文件
      $sourceFile = Get-ChildItem -Path "hello" -Filter "my-file-print-on-text-*-win-x64.exe" | Select-Object -First 1
      if ($sourceFile) {
        Copy-Item -Path $sourceFile.FullName -Destination "hello/my-file-print-on-text.exe" -Force
      } else {
        Write-Error "未匹配到符合规则的exe文件"
        exit 1
      }

如果需要写单行简化命令,写法如下:
Copy-Item -Path hello/my-file-print-on-text-*-win-x64.exe -Destination hello/my-file-print-on-text.exe -Force
注意源路径不需要加引号,通配符会自动解析,-Force参数会强制覆盖已存在的目标文件。


方式2:CMD脚本任务

如果使用CMD类型的任务,用原生copy命令写法:

- task: CmdLine@2
  inputs:
    script: |
      copy "hello\my-file-print-on-text-*-win-x64.exe" "hello\my-file-print-on-text.exe" /Y

注意CMD下路径分隔符用反斜杠\,/Y参数用来自动覆盖目标文件,不需要二次确认。


注意事项

  • 确保hello目录下同一时间只会存在一个符合my-file-print-on-text-*-win-x64.exe规则的文件,否则匹配到多个文件时复制操作会失败
  • 如果有路径包含空格的场景,使用第一种PowerShell匹配文件的写法,不会出现路径解析异常

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.25 08:24:03