5

We have a build/release pipeline that is finally working correctly, but the developer asked that we exclude the stage config files (Web.Dev.config, Web.Test.config, Web.Prod.config) as well as the artifact archive itself from the site/wwwroot.

As you can see, every time we deployed, these zip files have been getting stored in the site root as well. They aren't harmful but it doesn't look good:

wwwroot

This is the Release App Service Web Deploy YAML:

steps:
- task: AzureRmWebAppDeployment@4
  displayName: 'Azure App Service Deploy: project-123'
  inputs:
    azureSubscription: 'Azure Dev Service Connection'
    WebAppName: 'project-123'
    packageForLinux: '$(System.DefaultWorkingDirectory)/Project123 Dev Build Artifact/Release'
    enableCustomDeployment: true
    enableXmlTransform: true

How do we exclude those files after successful deployment?

Kudu dir structure:

kudu dir

halfer
  • 19,824
  • 17
  • 99
  • 186
Cataster
  • 3,081
  • 5
  • 32
  • 79

2 Answers2

4

Building on @theWinterCoder answer, Unfortunately, there doesn’t appear to be a way to honor the MSDeploySkipRules defined in the csproj file. Instead, files and folders can be skipped by defining the AdditionalArguments parameter of the Azure App Service Deploy (AzureRmWebAppDeployment) task.

Since there doesn’t appear to be any official documentation for the -skip rules, and the MSDeploy.exe documentation that Azure Pipelines references is out-of-date, in 2012, richard-szalay wrote a useful article, “Demystifying MSDeploy skip rules”, which provides a lot of details for anyone requiring additional control.

Brief Explanation:

The dirPath argument represents the Web Deploy Provider to skip a directory whilst the filePath argument is used to skip an individual file. The dirPath starts at wwwroot. For ASP.NET Core applications, there’s another wwwroot under wwwroot; as such, the absolutePath in that case would look like this: absolutePath=wwwroot\\somefoldername which would map to D:\home\site\wwwroot\wwwroot\somefoldername

Solution:

Therefore, since I’m skipping files, i set the web deploy provider to filePath, and since we’re not using .NET Core, we set absolutePath to Web.Dev.config. That would map to D:\home\site\wwwroot\Web.Dev.config. The same thing applies for the zip artifact, however, if we don’t prepend \\ before the wildcard it will fail with following error:

Error: Error: The regular expression '.zip’ is invalid. Error: parsing ".zip" - Quantifier {x,y} following nothing. Error count: 1.

-skip:objectName=filePath,absolutePath=Web.Dev.config 
-skip:objectName=filePath,absolutePath=Web.Prod.config 
-skip:objectName=filePath,absolutePath=Web.Test.config 
-skip:objectName=filePath,absolutePath=\\*.zip

or with regular expression:

-skip:objectName=filePath,absolutePath="Web.Dev.config|Web.Prod.config|Web.Test.config|\\*.zip"

Thats it

Dir

Cataster
  • 3,081
  • 5
  • 32
  • 79
1

You can add an additional arguments line to the yml that will tell it to skip certain files. It will look something like this:

AdditionalArguments: '-skip:objectName=dirPath,absolutePath=wwwroot\\Uploads'

More details can be found in this thread

  • Interesting, so does this skip them from deployment completely? or does it do its thing first to transform and web deploys from the zip file and then skips/excludes them from destination wwwroot? – Cataster Jul 02 '21 at 17:05
  • Also we we'rent using `MsDeploySkipRules` in csproj so idk the argument equivalent in our case. Like what am i supposed to put instead of `dirPath` in the objectName and absolutePath? Is `dirPath` and `wwwroot\\Uploads` native arguments or custom args? – Cataster Jul 02 '21 at 17:11
  • 1
    Truthfully I've never used this and just found this thread which should hopefully put you on your way to finding a solution :) I'm assuming you can alter the dirpath and wwwroot\\Uploads to reference your directory. So in your case wwwroot\\uploads would be the files you wish to omit, e.g. 379.zip (and have one for skip for each file). Annoyingly the documentation on it seems to be nonexistent which is a real shame – TheWinterCoder Jul 02 '21 at 18:33