Search code examples
gitazure-devopsazure-pipelines

Only fetch changed files


I want to modify this existing pipeline (which publishes to a test server) to only get files modified on the current branch. The issue I'm running into right now, is if one person pushes to branch A and the other to branch B, the pipeline overwrites all of the files with files from branch B, regardless of whether or not they were actually modified. I tried updating the checkout to fetchDepth: 0, but this didn't work.

trigger:
  branches:
    include:
    - '*'
    exclude:
    - main

pool:
  name: 'Default'  
  demands:
  - agent.os -equals Windows_NT  # Optional: Ensure it runs on Windows-based agents

steps:
  - checkout: self

  - task: WindowsMachineFileCopy@2
    inputs:
      SourcePath: '$(Build.Repository.LocalPath)'
      MachineNames: 'SERVER0TST'
      AdminUserName: 'ntdomain\user'
      AdminPassword: '$(user_password)'
      TargetPath: 'c:\inetpub\wwwroot'

Solution

  • Sounds like you'd be much better off merging whatever commits you want into one specific branch, and then having your pipeline just always track that branch. Pulling all new commits from every branch without overwriting other changes will fail any time changes in different branches occur in the same part of a file.

    I don't have any experience with Azure Pipelines, but I'd assume that similar to Jenkins pipelines, they're used for continuous testing, integration, and deployment. In any of those situations, you'll want the set of commits that go into a build to be recorded somewhere, not just assembled from the current state of all the branches, so that if there's a problem you can easily reproduce exactly what was built. Merging into a branch gives you that record.