首页 > 解决方案 > 带有通配符文件名的 Azure 管道 CopyFiles

问题描述

这有效

- task: CopyFiles@2
  condition: eq(variables.publishDeployables, true)
  displayName: 'Add README.md to output'
  inputs:
    sourceFolder: '$(Build.SourcesDirectory)'
    contents: 'README.MD'
    targetFolder: '$(Build.ArtifactStagingDirectory)'

但是这个:

- task: CopyFiles@2
  condition: eq(variables.publishDeployables, true)
  displayName: 'Add SQL to output'
  inputs:
    sourceFolder: '$(Build.SourcesDirectory)'
    contents: 'Setup*.sql'
    targetFolder: '$(Build.ArtifactStagingDirectory)

这是怎么回事?!

更新:日志输出

##[debug]Evaluating condition for step: 'Add SQL to output'
##[debug]Evaluating: eq(variables['publishDeployables'], True)
##[debug]Evaluating eq:
##[debug]..Evaluating indexer:
##[debug]....Evaluating variables:
##[debug]....=> Object
##[debug]....Evaluating String:
##[debug]....=> 'publishDeployables'
##[debug]..=> 'True'
##[debug]..Evaluating Boolean:
##[debug]..=> True
##[debug]..=> 'True'
##[debug]=> True
##[debug]Expanded: eq('True', True)
##[debug]Result: True
##[section]Starting: Add SQL to output
==============================================================================
Task         : Copy files
Description  : Copy files from a source folder to a target folder using patterns matching file paths (not folder paths)
Version      : 2.151.1
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/copy-files
==============================================================================
##[debug]agent.workFolder=C:\agent\_work
##[debug]loading inputs and endpoints
##[debug]loading ENDPOINT_AUTH_PARAMETER_SYSTEMVSSCONNECTION_ACCESSTOKEN
##[debug]loading ENDPOINT_AUTH_SCHEME_SYSTEMVSSCONNECTION
##[debug]loading ENDPOINT_AUTH_SYSTEMVSSCONNECTION
##[debug]loading INPUT_CLEANTARGETFOLDER
##[debug]loading INPUT_CONTENTS
##[debug]loading INPUT_FLATTENFOLDERS
##[debug]loading INPUT_OVERWRITE
##[debug]loading INPUT_PRESERVETIMESTAMP
##[debug]loading INPUT_SOURCEFOLDER
##[debug]loading INPUT_TARGETFOLDER
##[debug]loading SECRET_CHECKMARX_PASSWORD
##[debug]loading SECRET_SYSTEM_ACCESSTOKEN
##[debug]loaded 12
##[debug]check path : C:\agent\_work\_tasks\CopyFiles_5bfb729a-a7c8-4a78-a7c3-8d717bb7c13c\2.151.1\task.json
##[debug]set resource file to: C:\agent\_work\_tasks\CopyFiles_5bfb729a-a7c8-4a78-a7c3-8d717bb7c13c\2.151.1\task.json
##[debug]system.culture=en-US
##[debug]Contents=Setup*.sql
##[debug]SourceFolder=C:\agent\_work\12\s
##[debug]check path : C:\agent\_work\12\s
##[debug]TargetFolder=C:\agent\_work\12\a
##[debug]CleanTargetFolder=false
##[debug]OverWrite=false
##[debug]flattenFolders=false
##[debug]preserveTimestamp=false
##[debug]findPath: 'C:\agent\_work\12\s'
##[debug]findOptions.followSpecifiedSymbolicLink: 'true'
##[debug]findOptions.followSymbolicLinks: 'true'
##[debug]  C:\agent\_work\12\s (directory)
##[debug]  C:\agent\_work\12\s\.git (directory)
##[debug]  C:\agent\_work\12\s\.git\config (file)
##[debug]  C:\agent\_work\12\s\.git\description (file)
##[debug]  C:\agent\_work\12\s\.git\FETCH_HEAD (file)
##[debug]  C:\agent\_work\12\s\.git\HEAD (file)
##[debug]  C:\agent\_work\12\s\.git\hooks (directory)
##[debug]  C:\agent\_work\12\s\.git\hooks\applypatch-msg.sample (file)
...

为什么复制的东西会下降到我不感兴趣的子目录中?

标签: azure-devopsazure-pipelines

解决方案


带有通配符文件名的 Azure 管道 CopyFiles

如果您不想浪费时间搜索子目录,可以使用以下命令排除子目录!**\TestSubfolder\Setup*.sql

- task: CopyFiles@2
  condition: eq(variables.publishDeployables, true)
  displayName: 'Add SQL to output'
  inputs:
    sourceFolder: '$(Build.SourcesDirectory)'
    Contents: |
     Setup*.sql
     !**\TestSubfolder\Setup*.sql
     !**\TestSubfolder2\Setup*.sql
    targetFolder: '$(Build.ArtifactStagingDirectory)

并且在我测试时,Setup*.sql匹配文件Setup.sql,如果它不适合你,你可能需要检查文件的路径Setup.sql:</p>

在此处输入图像描述


推荐阅读