skip to Main Content

I want to upload my project via FTP to my webserver. Therefore I added a Pipeline in AzureDevOps. I have some folders (which have files and again some folders in it), which should not be uploaded to the webserver. For example the folders .git, .idea, blog and node_modules. My pipeline scripts looks like that:

trigger:
- test-stage

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: 'Copy-Item -Path $(System.DefaultWorkingDirectory)/.htaccess_test -Destination $(System.DefaultWorkingDirectory)/.htaccess -force'
- task: FtpUpload@2
  inputs:
    credentialsOption: 'inputs'
    serverUrl: '$(ftp-url)'
    username: '$(ftp-username)'
    password: '$(ftp-password)'
    rootDirectory: '$(System.DefaultWorkingDirectory)'
    remoteDirectory: '/test'
    trustSSL: true
    enableUtf8: false
    preservePaths: true
    filePatterns: |
      **
      !**/.git/**
      !**/.idea/**
      !**/blog/**
      !**/node_modules/**

Even tho the 4 folders are excluded, the content is being loaded on the webserver, for example here:
enter image description here

So my question is: What is wrong with my pipeline script, especially with the filePatterns?

2

Answers


  1. The issue might be related to the syntax or behavior of the pattern matching in Azure Pipelines.

    For testing, try and modify the file pattern in the FTP upload task to correctly exclude the specified folders content (**/xxx/**/* instead of **/xxx/**/).

    filePatterns: |
      **/*
      !**/.git/**/*
      !**/.idea/**/*
      !**/blog/**/*
      !**/node_modules/**/*
    

    Or:

    filePatterns: |
      **
      !**/.git/**
      !**/.idea/**
      !**/blog/**
      !**/node_modules/**
    

    Both solutions do not work… He uploads the .git directory anyway.

    Since both file pattern solutions are not working, there might be an underlying issue with how Azure Pipelines interprets the patterns or with the FTP upload task itself.

    Make sure the syntax used for the file patterns follows the Azure Pipelines file matching patterns.

    And enable verbose logging for the FTP upload task to get more detailed information on what the task is doing. That might provide insights into why it is uploading the .git directory.

    As a workaround, consider using multiple FTP upload tasks – one for each directory you want to upload, explicitly specifying the directory in the rootDirectory parameter. That would avoid having to use exclusion patterns.

    Or: add a pre-processing step in your pipeline to remove or move the directories you do not want to upload. For example, you could move .git, .idea, blog, and node_modules to a temporary location before the FTP upload task and then move them back afterward.

    steps:
    - script: |
        mv .git ../git_temp
        mv .idea ../idea_temp
        mv blog ../blog_temp
        mv node_modules ../node_modules_temp
      displayName: 'Pre-processing: Move directories out of upload path'
    
    - task: FtpUpload@2
      inputs:
        # your existing FTP upload configuration 
    
    - script: |
        mv ../git_temp .git
        mv ../idea_temp .idea
        mv ../blog_temp blog
        mv ../node_modules_temp node_modules
      displayName: 'Post-processing: Move directories back'
    

    That would temporarily moves the directories you do not want to upload out of the working directory, then moves them back after the upload is complete.

    Login or Signup to reply.
  2. I can reproduce the issue with the FtpUpload task used. But the filePatterns works as expected in CopyFiles task.

    So, as a workaround we can copy the project to a temp folder using the CopyFiles task with the filePatterns set, then upload the files from the temp folder using the FtpUpload task.

    For example:

    - task: CopyFiles@2
      inputs:
        SourceFolder: '$(System.DefaultWorkingDirectory)'
        Contents: |
          **
          !**/.git/**
          !**/.idea/**
          !**/blog/**
          !**/node_modules/**
        TargetFolder: '$(Build.ArtifactStagingDirectory)upload'
    
    - task: FtpUpload@2
      inputs:
        credentialsOption: 'inputs'
        serverUrl: '$(ftp-url)'
        username: '$(ftp-username)'
        password: '$(ftp-password)'
        rootDirectory: '$(Build.ArtifactStagingDirectory)upload'
        filePatterns: '**'
        remoteDirectory: '/upload/$(Build.BuildId)/'
        clean: false
        cleanContents: false
        preservePaths: true
        trustSSL: false
        enableUtf8: false
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search