azure-devopsazure-pipelinesazure-pipelines-build-taskminimatch

VSTS Minimatch pattern to exclude .git folder


I'm using VSTS and the build task FTP Upload. When the files and folders are uploaded to my FTP server the .git folder is always copied to the server too. I tried to exclude the .git folder with file pattern like following:

**
!(**/.git/**)

I don't know why it does not work but is there any way to tell the task with minimatch pattern to exclude folder explicitly?


Solution

  • The minimatch pattern for the file patterns option in FTP Upload task only can exclude the folders. Such as if you use the !**\.git\** as File patterns, it will only remove the .git folder and the subfolders in it, but the files in these folder still upload to FTP server.

    If you don’t want the .git folder (including the files in it) to be uploaded to FTP, you can add a Copy Files task before FTP Upload task. Detail settings as below:

    Copy Files task

    Source Folder: $(Build.SourcesDirectory)

    Contents:

    **
    !**\.git\**
    

    Target Folder: $(Build.ArtifactStagingDirectory)\upload

    FTP Upload task

    You just need to change below settings,

    Source folder: $(Build.ArtifactStagingDirectory)\upload

    File patterns: **

    Now exclude the files in .git folder, all the files and folders are upload to FTP server.