Watch out for this when you're doing an FTP Deploy for Azure App Services

Watch out for this when you're doing an FTP Deploy for Azure App Services

Wow, these last few weeks has been a lot of focus on DevOps. As I mentioned on Twitter I'm currently assigned on moving 4 of our clients projects setups from BitBucket + Teamcity + Octopus Deploy setup to Azure DevOps (which probably why the blog has been very DevOps focused lately).

This week I have been moving a few of our static frontend applications from traditional servers to Azure using FTP Upload (for various reasons we choose this release setup due to some access limitations in the Active Directory, not relevant for this article but worth mentioning).

While doing so, I stumbled upon two pitfalls that I first thought was due to my limited knowledge about this release task (I usually go with Deploy to App Service) but when I discussed this "mistake" with one of my coworkers he mentioned that he had had the exact same mistakes a few days ago.

-"Both these configurations are "non-defaults" so they are very easy mistakes to make."

So I thought if the two of us both had the exact to mistakes happen to us, the chances are we are not the only two. Both these configurations are "non-defaults" so they are very easy mistakes to make. Hence this blog post.

Remote directory: /site/wwwroot

When you create a new FTP Upload release pipeline task, you will get this default YAML:

steps:
- task: FtpUpload@2
  displayName: 'FTP Upload'
  inputs:
    credentialsOption: inputs
    serverUrl: {serverUrl}
    username: {username}
    password: {password}
    rootDirectory: $(System.DefaultWorkingDirectory)/drop

Unless you actively specify a remote directory your files will be deployed to "/upload/$(Build.BuildId)/" on the remote server. Which is probably not what you want. And don't make my mistake and specify "/" as your remote directory, since this will deploy your files outside of the App Service website root folder. 😱 This is definitely not what you want.

Instead, you should specify "/site/wwwroot" as your remote directory when you are using an Azure App Service:

steps:
- task: FtpUpload@2
  displayName: 'FTP Upload'
  inputs:
    credentialsOption: inputs
    serverUrl: {serverUrl}
    username: {username}
    password: {password}
    rootDirectory: $(System.DefaultWorkingDirectory)/drop
    remoteDirectory: /site/wwwroot


Preserve file paths: True

This is another configuration that is not default and it is also hidden under an "Advanced" section if you aren't using YAML.

It's the "Preserve file paths" checkbox. This is not checked by default and if you leave it this way, all your files will be deployed in to the same root directory regardless of the folder structure on your source artifact.

In other word:

-"The folder structure of your source will not be preserved on the target server."

Again, probably (most likely) this is not what you want. You probably want your folder structure to be the same as the structure you are deploying and not have all your files in one single directory. So remember to tick this checkbox or use this YAML:

steps:
- task: FtpUpload@2
  displayName: 'FTP Upload'
  inputs:
    credentialsOption: inputs
    serverUrl: {serverUrl}
    username: {username}
    password: {password}
    rootDirectory: $(System.DefaultWorkingDirectory)/drop
    remoteDirectory: /site/wwwroot
    preservePaths: true

Best of luck.
Cheers friends! ❤️