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

Azure DevOps Pipeline打包无扩展名文件被误判为目录的问题

解决Azure DevOps ArchiveFiles任务误把无扩展名文件当目录的问题

方案1:直接列出所有要打包的文件

如果utils是无扩展名的文件,别让任务猜路径类型,直接把所有要打包的文件都列出来。比如你要打包utils、file1.txt、file2.sh三个文件,YAML这么写:

- task: ArchiveFiles@2
  displayName: 'Archive target files'
  inputs:
    rootFolderOrFile: |
      $(Build.SourcesDirectory)/utils
      $(Build.SourcesDirectory)/file1.txt
      $(Build.SourcesDirectory)/file2.sh
    includeRootFolder: false
    archiveType: '$(archive.type)'
    archiveFile: '$(archive.fileName)'
    replaceExistingArchive: false
    verbose: true

直接指定每个文件的路径,任务会逐个识别,不会把utils当成目录。

方案2:给文件路径加通配符强制匹配

如果utils就在指定目录下,给路径加个*通配符,强制任务按文件匹配:

- task: ArchiveFiles@2
  displayName: 'Add utils file to archive'
  inputs:
    rootFolderOrFile: '$(Build.SourcesDirectory)/utils*'
    includeRootFolder: false
    archiveType: '$(archive.type)'
    archiveFile: '$(archive.fileName)'
    replaceExistingArchive: false
    verbose: true

通配符会让任务忽略“无扩展名=目录”的误判逻辑,直接匹配文件。

方案3:先确认文件类型(排查用)

要是不确定是不是文件本身的问题,加个PowerShell任务先验证:

- task: PowerShell@2
  displayName: 'Check utils file type'
  inputs:
    targetType: 'inline'
    script: |
      $filePath = "$(Build.SourcesDirectory)/utils"
      if (Test-Path -Path $filePath -PathType Leaf) {
          Write-Host "utils is a file"
      } elseif (Test-Path -Path $filePath -PathType Container) {
          Write-Host "utils is a directory"
      } else {
          Write-Host "utils does not exist"
      }

这步能帮你确认utils到底是文件还是真的目录,也能排查路径写错的情况。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.30 18:57:09