Search code examples
azure-devopstfsbuildazure-pipelines

Copy one file in target directory on deploy from visual studio team services


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?


Solution

  • 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:

    Project\bin\x86\Release\project.exe
    SomeScripts\**\*
    

    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:

    Project\bin\$(BuildPlatform)\$(BuildConfiguration)\project.exe
    SomeScripts\**\*
    

    If you want the project.exe to be in the root instead of the structure you need to use a Copy 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.