4

In my TFS 2017 build definition, I am trying to copy a folder with a specific name (Package) towards my Artifacts directory. I am only interested in the specific folder itself, not in it's parent folders.

Can someone enlighten me on how I should make this work?

Current configuration for the Copy Files task: Source: $(agent.builddirectory) Contents: **\Package*** Target Folder: $(build.artifactstagingdirectory)\MyArtifact

This results in the following folderstructure while my only interest is the Package folder: \MyArtifact\folderX\s\folderY\folderZ\folderA\Package

Ben Thaens
  • 213
  • 3
  • 9

3 Answers3

9

With TFS2017update1 and above, VSTS, you could simply check Flatten Folders under Advanced option in Copy Files Task. The easiest solution for now.

enter image description here

This will flatten the folder structure and copy all files into the specified target folder.

Not sure if you are working on 2017 release version, and there is no Flatten Folders option. You need to specify the copy root if you want to copy files only without folder structure. You can use $(Build.StagingDirectory) as a target for this. Afterwards use the Publish task with $(Build.StagingDirectory) as copy root and publish everything from this root to the drop.

Detail step and screenshot please take a look at the answer from Eddie in this question: Copy one file in target directory on deploy from visual studio team services

PatrickLu-MSFT
  • 49,478
  • 5
  • 35
  • 62
  • Thanks for your advice Patrick. I do have the update 1 but I don't want to flatten the folders as my 'Package' folder contains the output of a WCF project: some .svc's in the top level and a bin folder with dll's. I would like to preserve to keep this structure... – Ben Thaens Oct 10 '17 at 06:11
  • @BenThaens If so you could use the option 2, just copy the files some with structure and some without structure to a medium path such as `Build.StagingDirectory` instead of directly using `builddirectory` – PatrickLu-MSFT Oct 10 '17 at 06:26
1

If the relative path to "package" does not change, you can specify the detailed path in "Source" to achieve the feature you want.

For example, configure the Copy Files Task:

Source Folder to: $(agent.builddirectory)\folderY\folderZ\folderA\Package

Contents to: **

Target Folder to: $(build.artifactstagingdirectory)\MyArtifact\Package

You will get the folder structure you want.

Eddie Chen - MSFT
  • 29,708
  • 2
  • 46
  • 60
1

While all answers were correct in some way, it was not what I intended to achieve. I ended up creating my own PowerShell script to copy the package folder and it's contents to the Staging Directory:

$BasePath = [System.IO.Path]::GetDirectoryName("$(SolutionPath)")
$Search = "PackageTmp"
$Destination = "$(Build.StagingDirectory)"

Get-ChildItem -Path $BasePath -Filter $Search -Directory -Recurse | Copy-Item -Destination {Join-Path $Destination $(ArtifactName)} -Recurse -Force
Ben Thaens
  • 213
  • 3
  • 9