使用此工作,使用比對模式,將檔案從源資料夾複製到目標資料夾。 (比對模式只會比對檔案路徑,而不是資料夾路徑)。
語法
# Copy files v2
# Copy files from a source folder to a target folder using patterns matching file paths (not folder paths).
- task: CopyFiles@2
inputs:
#SourceFolder: # string. Source Folder.
Contents: '**' # string. Required. Contents. Default: **.
TargetFolder: # string. Required. Target Folder.
# Advanced
#CleanTargetFolder: false # boolean. Clean Target Folder. Default: false.
#OverWrite: false # boolean. Overwrite. Default: false.
#flattenFolders: false # boolean. Flatten Folders. Default: false.
#preserveTimestamp: false # boolean. Preserve Target Timestamp. Default: false.
#retryCount: '0' # string. Retry count to copy the file. Default: 0.
#delayBetweenRetries: '1000' # string. Delay between two retries. Default: 1000.
#ignoreMakeDirErrors: false # boolean. Ignore errors during creation of target folder. Default: false.
# Copy files v2
# Copy files from a source folder to a target folder using patterns matching file paths (not folder paths).
- task: CopyFiles@2
inputs:
#SourceFolder: # string. Source Folder.
Contents: '**' # string. Required. Contents. Default: **.
TargetFolder: # string. Required. Target Folder.
# Advanced
#CleanTargetFolder: false # boolean. Clean Target Folder. Default: false.
#OverWrite: false # boolean. Overwrite. Default: false.
#flattenFolders: false # boolean. Flatten Folders. Default: false.
#preserveTimestamp: false # boolean. Preserve Target Timestamp. Default: false.
輸入
SourceFolder
-
源數據夾
string
。
選擇性。 包含您要複製之檔案的資料夾。 如果資料夾是空的,則工作會從存放庫的根資料夾複製檔案,就像指定了 $(Build.SourcesDirectory)
一樣。
如果您的組建在來源目錄之外產生成品,請指定 $(Agent.BuildDirectory)
,從為管線建立的目錄複製檔案。
Contents
-
內容
string
。 必須的。 預設值: **
。
要包含在複本中的檔案路徑。 此字串支援多行比對模式。
例如:
-
*
會複製指定之源資料夾中的所有檔案。 -
**
會複製指定之源資料夾中的所有檔案,以及所有子資料夾中的所有檔案。 -
**\bin\**
會以遞歸方式從任何 bin 資料夾複製所有檔案。
此模式只用來比對檔案路徑,而非資料夾路徑。 指定模式,例如 **\bin\**
,而不是 **\bin
。
在 []
中包裝特殊字元可用來逸出檔名中的常值 glob 字元。 例如,常值檔名 hello[a-z]
可以逸出為 hello[[]a-z]
。 如需詳細資訊,請參閱 檔案比對模式參考。
使用符合組建代理程式類型的路徑分隔符。 例如,/
必須用於 Linux 代理程式。 以下顯示更多範例。
TargetFolder
-
目標資料夾
string
。 必須的。
將包含複製檔案的目標資料夾或 UNC 路徑。 您可以使用 變數。 範例: $(build.artifactstagingdirectory)
.
CleanTargetFolder
-
清除目標資料夾
boolean
。 預設值: false
。
選擇性。 在複製程式之前,刪除目標資料夾中的所有現有檔案。
OverWrite
-
覆寫
boolean
。 預設值: false
。
選擇性。 取代目標資料夾中的現有檔案。
flattenFolders
-
扁平化資料夾
boolean
。 預設值: false
。
選擇性。 壓平資料夾結構,並將所有檔案複製到指定的目標資料夾。
preserveTimestamp
-
保留目標時間戳
boolean
。 預設值: false
。
使用原始源檔保留目標檔時間戳。
retryCount
-
重試計數以複製檔
string
。 預設值: 0
。
指定複製檔案的重試計數。 此字串對於間歇性問題(如遠端主機上的 UNC 目標路徑)非常有用。
delayBetweenRetries
-
兩次重試之間的延遲。
string
。 預設值: 1000
。
指定兩次重試之間的延遲。 此字串對於間歇性問題(如遠端主機上的 UNC 目標路徑)非常有用。
ignoreMakeDirErrors
-
忽略創建目標資料夾期間的錯誤。
boolean
。 預設值: false
。
忽略在創建目標資料夾期間發生的錯誤。 此字串可用於避免一個目標資料夾中的多個代理並行執行任務的問題。
工作控制選項
除了工作輸入之外,所有工作都有控制選項。 如需詳細資訊,請參閱 控制項選項和一般工作屬性。
輸出變數
沒有。
備註
如果沒有相符的檔案,工作仍會回報成功。
- 如果
Overwrite
目標false
資料夾中已存在匹配的檔,則任務不會報告失敗,但會記錄該檔已存在並跳過它。 - 如果
Overwrite
是true
並且目標資料夾中已存在匹配的檔,則匹配的檔將被覆蓋。
範例
將檔案複製到構件暫存目錄併發佈
steps:
- task: CopyFiles@2
inputs:
contents: '_buildOutput/**'
targetFolder: $(Build.ArtifactStagingDirectory)
- task: PublishBuildArtifacts@1
inputs:
pathToPublish: $(Build.ArtifactStagingDirectory)
artifactName: MyBuildOutputs
複製可執行檔和自述檔
目標
您要複製執行這個 C# 主控應用程式所需的自述檔案與檔案:
`-- ConsoleApplication1
|-- ConsoleApplication1.sln
|-- readme.txt
`-- ClassLibrary1
|-- ClassLibrary1.csproj
`-- ClassLibrary2
|-- ClassLibrary2.csproj
`-- ConsoleApplication1
|-- ConsoleApplication1.csproj
備註
ConsoleApplication1.sln 包含一個包含 .dll 和 .exe 檔的 bin 資料夾,請參閱下面的結果以查看行動的內容!
在 Variables 選項卡上, $(BuildConfiguration)
設定為 release
。
具有多個匹配模式的範例:
steps:
- task: CopyFiles@2
displayName: 'Copy Files to: $(Build.ArtifactStagingDirectory)'
inputs:
Contents: |
ConsoleApplication1\ConsoleApplication1\bin\**\*.exe
ConsoleApplication1\ConsoleApplication1\bin\**\*.dll
ConsoleApplication1\readme.txt
TargetFolder: '$(Build.ArtifactStagingDirectory)'
具有 OR 條件的範例:
steps:
- task: CopyFiles@2
displayName: 'Copy Files to: $(Build.ArtifactStagingDirectory)'
inputs:
Contents: |
ConsoleApplication1\ConsoleApplication1\bin\**\?(*.exe|*.dll)
ConsoleApplication1\readme.txt
TargetFolder: '$(Build.ArtifactStagingDirectory)'
具有 NOT 條件的範例:
steps:
- task: CopyFiles@2
displayName: 'Copy Files to: $(Build.ArtifactStagingDirectory)'
inputs:
Contents: |
ConsoleApplication1\**\bin\**\!(*.pdb|*.config)
!ConsoleApplication1\**\ClassLibrary*\**
ConsoleApplication1\readme.txt
TargetFolder: '$(Build.ArtifactStagingDirectory)'
內容部分包含變數的範例
- task: CopyFiles@2
inputs:
Contents: '$(Build.Repository.LocalPath)/**'
TargetFolder: '$(Build.ArtifactStagingDirectory)'
結果
這些檔案複製到暫存目錄:
`-- ConsoleApplication1
|-- readme.txt
`-- ConsoleApplication1
`-- bin
`-- Release
| -- ClassLibrary1.dll
| -- ClassLibrary2.dll
| -- ConsoleApplication1.exe
複製源目錄中除 .git 資料夾之外的所有內容
具有多個匹配模式的範例:
steps:
- task: CopyFiles@2
displayName: 'Copy Files to: $(Build.ArtifactStagingDirectory)'
inputs:
SourceFolder: '$(Build.SourcesDirectory)'
Contents: |
**/*
!.git/**/*
TargetFolder: '$(Build.ArtifactStagingDirectory)'
需求
要求 | 說明 |
---|---|
管線類型 | YAML,傳統組建 |
執行於 | Agent、DeploymentGroup |
要求 | 沒有 |
能力 | 此工作不符合作業中後續工作的任何需求。 |
命令限制 | 此工作會使用下列 命令限制執行: 受限制 |
Settable 變數 | 此工作有權 設定下列變數:已停用設定變數 |
代理程式版本 | 2.182.1 或更新 |
工作類別 | 效用 |
要求 | 說明 |
---|---|
管線類型 | YAML,傳統組建 |
執行於 | Agent、DeploymentGroup |
要求 | 沒有 |
能力 | 此工作不符合作業中後續工作的任何需求。 |
命令限制 | 任意 |
Settable 變數 | 任意 |
代理程式版本 | 1.91.0 或更新 |
工作類別 | 效用 |
另請參閱
- 檔案比對模式參考
- 如何使用這項工作來發佈成品
- 瞭解如何使用 詳細信息記錄 進行 疑難解答。