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:
So my question is: What is wrong with my pipeline script, especially with the filePatterns?
2
Answers
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/**/
).Or:
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
, andnode_modules
to a temporary location before the FTP upload task and then move them back afterward.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.
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: