Azure Pipelines: Exclude folders using Azure App Service Deploy
S

2

4

I have an Azure DevOps Pipeline which includes an Azure App Service Deploy task (AzureRmWebAppDeployment) for deploying an ASP.NET Core 3.1 project:

- task: AzureRmWebAppDeployment@4
  inputs:
    ConnectionType: 'AzureRM'
    azureSubscription: 'Azure Subscription(01234567-89ab-cdef-0123-456789abcdef)'
    appType: 'webApp'
    WebAppName: 'MyStagingSite'
    packageForLinux: '$(Build.ArtifactStagingDirectory)/**/*.zip'
    enableCustomDeployment: true
    DeploymentType: 'webDeploy'
    enableXmlTransform: false
    enableXmlVariableSubstitution: true
    RemoveAdditionalFilesFlag: false

The Azure App Service destination, however, contains files in several pre-established folders which are managed independent of the continuous delivery process. We would like to use the Remove additional files at destination flag (RemoveAdditionalFilesFlag) while leaving those folders intact.

Disclaimer: I don't consider this a best practice and, in the future, we will be moving these files off to a separate storage location. Until then, I'd like to find a solution that will work resolve this.

In Visual Studio 2019, we achieve this by excluding those files from our publishing process using the MsDeploySkipRules in our csproj file:

<Project Sdk="Microsoft.NET.Sdk.Web">
  …
  <ItemGroup>
    <MsDeploySkipRules Include="CustomSkipFolder">
      <ObjectName>dirPath</ObjectName>
      <AbsolutePath>wwwroot\\Uploads</AbsolutePath>
    </MsDeploySkipRules>
  </ItemGroup>
</Project>

This approach works well for Visual Studio and is honored by its web deployment publishing process. These rules do not appear to be honored by the AzureRmWebAppDeployment task, however, even when using the "Web Deploy" deployment method (DeploymentType).

Is there a way to honor the MsDeploySkipRules when using the AzureRmWebAppDeployment task? If not, if there a way to provide a list of folders which should be skipped or ignored as part of the deployment process? Or, alternatively, if there another task that will permit one of these options when publishing to an Azure App Service?

Note: I also posted this to the DevOps Beta, but as the site hasn't reached critical mass yet, I'm cross-posting it here.

Setter answered 5/3, 2020 at 1:31 Comment(0)
L
1

Is there a way to honor the MsDeploySkipRules when using the AzureRmWebAppDeployment task?

Not sure if there's a way to apply MsDeploySkipRules but there's exising way to skip specidic files during the deplyment process.

For detailed information, please check Exclude/Skip files in VSTS Build and release .

As suggested in the above thread, add additional arguments to your task to skip the specific files.

Fill your filepath in the skip argument. More information at Azure App Service Deploy task (press Ctrl+ F to search for additional arguments) and Web Deploy Operation Settings for the syntax.

Please have a try and hope this could help.

Ladino answered 5/3, 2020 at 8:45 Comment(3)
Does this help skip or ignore your folders? If so, you can accept it. Or if you met some issues when implementing it, please fell free to tell. Thanks!Ladino
I was definitely hoping to find a way to centralize this configuration, but at least this gives me an opportunity to reinstate RemoveAdditionalFilesFlag without worrying about these exceptions. Thank you! I've implemented this and confirmed that it works as expected. I also apologize for taking so long to mark this as the accepted answer; I wanted to confirm that it worked before doing so.Setter
Aside, do you know where the latest documentation for msdeploy.exe is? I've been unable to find it, and every source (including the Azure Pipelines task) points to the 2014 documentation you linked to. The issue is it doesn't actually document the parameters or syntax for using the -skip: rules. I was able to infer this based on my csproj's <MsDeploySkipRules /> directives, and I've found third-party documentation, but can't find official documentation from Microsoft.Setter
S
7

As @yang-shen-msft notes in the accepted answer, 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 Additional Arguments (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, the following provides additional details.

Translating the csproj format

First, it's useful to recognize that when you deploy a project via Visual Studio, it's simply taking the MSDeploySkipRules configured in the csproj file and adding them to its internal call of msdeploy.exe as -skip rules. So, given the following rule defined in the csproj:

<Project Sdk="Microsoft.NET.Sdk.Web">
  …
  <ItemGroup>
    <MsDeploySkipRules Include="CustomSkipFolder">
      <ObjectName>dirPath</ObjectName>
      <AbsolutePath>wwwroot\\Uploads</AbsolutePath>
    </MsDeploySkipRules>
  </ItemGroup>
</Project>

The -skip rule is interpreted as:

msdeploy.exe -skip:objectName=dirPath,absolutePath=wwwroot\\Uploads

Translating this to the Azure App Service Deploy (AzureRmWebAppDeployment) task, the resulting yml might look like:

- task: AzureRmWebAppDeployment@4
  inputs:
    ConnectionType: 'AzureRM'
    azureSubscription: 'Azure Subscription'
    appType: 'webApp'
    WebAppName: 'MyStagingSite'
    packageForLinux: '$(Build.ArtifactStagingDirectory)/**/*.zip'
    enableCustomDeployment: true
    DeploymentType: 'webDeploy'
    enableXmlTransform: false
    enableXmlVariableSubstitution: true
    RemoveAdditionalFilesFlag: true
    AdditionalArguments: '-skip:objectName=dirPath,absolutePath=wwwroot\\Uploads'

Note that multiple -skip rules can be defined on the same msdeploy.exe call.

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

-skip Rules Documentation

Unfortunately, as mentioned above, there doesn't appear to be any official, first-party documentation for the -skip rules on msdeploy.exe. The 2014 documentation acknowledges them, and provides two examples, but doesn't expand on the options. That said, way back in 2012, @richard-szalay wrote a useful article, "Demystifying MSDeploy skip rules", which provides a lot of details for anyone requiring additional control.

Additional Notes

  • The ObjectName refers to the Web Deploy Provider, which can be used to update far more than just the file system.

  • I am setting ObjectName to the dirPath Web Deploy Provider so that I can skip entire directories. If you want to skip files, use filePath instead.

  • Both dirPath and filePath accept regular expressions in the AbsolutePath, potentially allowing repetitive rules following a consistent pattern to be consolidated.

  • The AbsolutePath is actually relative to your publishing root—e.g., D:\home\site\wwwroot on an Azure App Service.

  • As I am publishing an ASP.NET Core site, my static files are, by convention, in a nested wwwroot folder, thus my setting:

    absolutePath=wwwroot\\Uploads
    

    actually maps to:

    D:\home\site\wwwroot\wwwroot\Uploads
    
Setter answered 20/3, 2020 at 20:23 Comment(9)
On Kudu, this is my path: D:\home\site\wwwroot. So would it be D:\home instead of dirPath and site\wwwroot instead of wwwroot\Uploads?Murton
@Cataster: Good question. My base path is the same as yours. The dirPath argument represents the Web Deploy Provider; if you want to skip a directory, you likely want to stick with dirPath—or filePath if you want to skip an individual file. The dirPath starts at wwwroot. I am using ASP.NET Core, so there’s another wwwroot under wwwroot; as such, my absolutePath=wwwroot\\Uploads actually maps to D:\home\site\wwwroot\wwwroot\Uploads. Hope this helps!Setter
@Cataster: As an aside, it is my understanding that dirPath also accepts regular expressions, so if there’s a predictable pattern to the directories you want to skip, you may be able to consolidate them into a single rule. I haven’t had the need for this, so haven’t confirmed the functionality or idiosyncrasies of the syntax, but it’s useful to be aware of.Setter
Thanks jeremy. So since I'm skipping files, i set the web deploy provider to filePath, and set absolutePath to wwwroot\\web.dev.config, but the file wasnt skipped...so I'm guessing absolutePath would be the file I'm skipping directly? Since mine is not .NET Core?Murton
@Cataster: Since you're not using .NET Core, you'll probably just want to set absolutePath to web.dev.config. That would map to D:\home\site\wwwroot\web.dev.config.Setter
Jeremy, setting the absolutePath to the file directly worked!!! Thank you so much!! :D btw, how do i skip files using wildcard? For example, *.zip but that resulted in error Error: Error: The regular expression '*.zip' is invalid. Error: parsing "*.zip" - Quantifier {x,y} following nothing. Error count: 1.Murton
nvm i figured it out, i had to use \\ along with the wildcard \\*.zip.Murton
@Cataster: Glad to hear! FYI: I’ve now updated my answer to include notes from this exchange so it’s easy for future readers to get this information.Setter
Once again thank you very much Jeremy, you really nailed it down while MSFT lounging around for the past 3 days since a question I posted had been opened. At the very least I can reward you with an upvote :)Murton
L
1

Is there a way to honor the MsDeploySkipRules when using the AzureRmWebAppDeployment task?

Not sure if there's a way to apply MsDeploySkipRules but there's exising way to skip specidic files during the deplyment process.

For detailed information, please check Exclude/Skip files in VSTS Build and release .

As suggested in the above thread, add additional arguments to your task to skip the specific files.

Fill your filepath in the skip argument. More information at Azure App Service Deploy task (press Ctrl+ F to search for additional arguments) and Web Deploy Operation Settings for the syntax.

Please have a try and hope this could help.

Ladino answered 5/3, 2020 at 8:45 Comment(3)
Does this help skip or ignore your folders? If so, you can accept it. Or if you met some issues when implementing it, please fell free to tell. Thanks!Ladino
I was definitely hoping to find a way to centralize this configuration, but at least this gives me an opportunity to reinstate RemoveAdditionalFilesFlag without worrying about these exceptions. Thank you! I've implemented this and confirmed that it works as expected. I also apologize for taking so long to mark this as the accepted answer; I wanted to confirm that it worked before doing so.Setter
Aside, do you know where the latest documentation for msdeploy.exe is? I've been unable to find it, and every source (including the Azure Pipelines task) points to the 2014 documentation you linked to. The issue is it doesn't actually document the parameters or syntax for using the -skip: rules. I was able to infer this based on my csproj's <MsDeploySkipRules /> directives, and I've found third-party documentation, but can't find official documentation from Microsoft.Setter

© 2022 - 2024 — McMap. All rights reserved.