Slimshadddyyy
Slimshadddyyy

Reputation: 4081

Azure Devops FTP Upload - Upload only changed files on Remote Server

The current setup is as below

The dev team clones Azure Repo into local git project and any staged changes are committed via Git and pushed to specific branch of Azure DevOps. In this setup we would want to upload the changes to external FTP servers and avoid manual upload. Currently trying to use Azure Devops FTP Upload Task (https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/ftp-upload?view=azure-devops), and able to successfully run pipeline and publish artifact. However, this script uploads all the files and folders at specified path and not just the staged changed. YAML script as below

trigger:
- main

pool:
  vmImage: 'ubuntu-latest'

variables:
 - name: StagingRepo
   value: $(System.DefaultWorkingDirectory)

steps:

- publish: $(StagingRepo)
  artifact: Staging Repo

- task: FtpUpload@2
  displayName: 'FTP Upload'
  inputs:
    credentialsOption: inputs
    serverUrl: 'ftps://00.00.00.00:22'
    username: ftp-username
    password: ftp-password
    rootDirectory: '$(StagingRepo)'
    remoteDirectory: '/home/public_html'
    clean: false
    cleanContents: false
    preservePaths: false
    trustSSL: true

PROBLEM

Any way that we can only upload only committed changes to FTP instead of uploading the whole repo/files? From the docs, new build pipelines update only the changed files but in this case it is uploading everything.

Thanks

Upvotes: 1

Views: 1229

Answers (1)

wade zhou - MSFT
wade zhou - MSFT

Reputation: 8310

As per the task doc: enter image description here

You are uploading the whole working directory(which store your repo content) to remote FTP server.

Please fix remoteDirectory as a directory not a file /home/public_html.

If you'd like to only upload committed changes to FTP, you need to find the changed files firstly. You can find the yaml script in answer here.

The problem is to upload the files, if you use task "task: FtpUpload@2", you can put the changed files into a folder and upload the folder content to remote server, but the changed files will in same folder which is different with git repo content.

If you'd to sync the change to remote server which means keeping the same file path in repo content, you need to install git-ftp. Please refer to the link here and here. Use git script instead of task to upload the files.

Edit:

This an Extension FTP Uploader which support "Ignore unchanged files".

enter image description here

Upvotes: 2

Related Questions