Automate Azure Devops (FTP Upload) and Git to upload on Remote Server

The current setup is as below

  • Version Control - Git
  • Repos and Branch hosted on - Azure DevOps
  • Codebase - External server

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://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/ftp-upload?view=azure-devops), however facing issues; yaml script as below

trigger:
- main

pool:
  vmImage: 'ubuntu-latest'

variables:
  phpVersion: 7.4
  webAppName: 'Test Project'
  buildConfiguration: 'Release'
  vmImageName: 'ubuntu-latest'

steps:

- publish: $(System.DefaultWorkingDirectory)/AzureRepoName
  artifact: Test Project Deploy

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

PROBLEM

Following errors occur when I commit (for test purposes) something.

Starting: PublishPipelineArtifact
==============================================================================
Task         : Publish Pipeline Artifacts
Description  : Publish (upload) a file or directory as a named artifact for the current run
Version      : 1.199.0
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/publish-pipeline-artifact
==============================================================================
Artifact name input: Test Project Deploy
##[error]Path does not exist: /home/vsts/work/1/s/AzureRepoName
Finishing: PublishPipelineArtifact

I want to upload any staged change that is committed to main branch on Azure Devops to be automatically deploy on the remote FTP server

Thanks

1 answer

  • answered 2022-05-07 10:56 Gurpreet

    On checkout devops agent will create /home/vsts/work/1/s/AzureRepoName folder with your source but actually when the checkout happens the /home/vsts/work/1/s folder is the repository root i.e. there is no AzureRepoName folder in there. so what you need is to publish /home/vsts/work/1/s folder itself as the artifact. also your ftp upload task should use rootDirectory: '$(System.DefaultWorkingDirectory)/AzureRepoName'

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum