I'm using VSTS as a build server, and while building I want to copy the bin folder contents to the root of the target, and also custom files from another folder to this target. MSDN suggests I use a minimatch pattern, but it's copying files with the subdirectory structure. I'm not interested in restoring the structure.
For example, I am getting this folder structure:
Project
MyProjectFiles
bin
x86 (it's build configuration)
Project.exe
Other project files
Project.sln
SomeScrips
script1.ps1
But I want to receive this folder structure:
Project.exe
SomeScripts
script.ps1
Which minimatch pattern can I use for my requirements?
With TFS2017update1 and above, VSTS, you could simply check Flatten Folders under Advanced option in Copy Files Task. The easiest solution for now.
With the new web based build system you can use multiple patterns in a single step. Therefore you can do something like this for your case:
Or if you have the build platform and configuration in a variable (eg.
BuildPlatform
/BuildConfiguration
) which you also use in the build step you could use them in the pattern:If you want the
project.exe
to be in the root instead of the structure you need to use aCopy Task
to stage your files in the desired structure first. 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."Flatten Folders" option in "Advanced" section of "Copy Files" step.
If you are using TFS Online (Visual Studio Online) and don't need to copy the folder structure use "Flatten Folders" option in "Advanced" section of "Copy Files" step in your build definition
The "flattenFolders" option is also available as a YAML task parameter. The following code excerpt shows a CopyFiles@2 task which copyies the build output to the $(Build.ArtifactStagingDirectory). When I specify the option
flattenFolders: true
the nested folder structurebin\release\...\My.exe
is flattened, means the exe files is copied to the root of $(Build.ArtifactStagingDirectory).Further documentation concerning the CopyFiles task can be found here: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/copy-files?view=vsts&tabs=yaml
For those who would like to have a PowerShell script to use in your build server, here is a working (at least, on my build server ;)) sample:
Here is the script being used in a PowerShell build step:
You need to specify the copy root if you want to copy files only without folder structure. Since the project.exe is in a different path with script.ps1 file, you need to copy them in different copy task.
Following the steps below:
Now you should get the things like following in drop folder: