Search code examples
azure-devopsazure-pipelinesmultistage-pipeline

Multi-stage YAML pipeline does not apply environment-specific XML transformation


I transformed steps executed within a typical release pipeline into a multi-stage YAML pipeline.

The problem is that the Web.config (XML) transformation applied by the AzureRmWebAppDeployment@4 task does not work as previously anymore.

The documented approach of this behavior is that first the release config is being used for the transformation and the environment-specific config follows.

From the logs I can see that the Web.Release.config is applied, but there is no other transformation happening for the Web.TA.config (environment-specific config) even though it is present and the stage name matches the config name.

I have the following (simplified) YAML file for a multi-stage pipeline:

trigger: none

variables:
  azureSubscriptionProject: 'SubscriptionName'
  artifactDropDirectory: '$(Agent.BuildDirectory)/ProjectName'

stages:
- stage: Build
  jobs:
  - job: Build
    pool:
      vmImage: windows-2019
      demands:
      - msbuild
      - visualstudio
      - vstest
    variables:
      buildConfiguration: 'Release'
      buildPlatformSolutionLevel: 'Any CPU'
      buildPlatformProjectLevel: 'AnyCPU'
    steps:
    - template: azure-pipelines-ci-build-steps-template.yml
    - template: azure-pipelines-ci-build-publishing-steps-template.yml
- stage: TA
  dependsOn: Build
  jobs:
  - deployment: TA
    pool:
      vmImage: windows-2019
    environment: 'TA'
    timeoutInMinutes: 0
    strategy:
      runOnce:
        deploy:
          steps:
          # ...          
          - task: AzureRmWebAppDeployment@4
            displayName: 'Deploy ProjectName'
            inputs:
              azureSubscription: $(azureSubscriptionProject)
              webAppName: '$(AzureResourcesPrefix)-project-name'
              package: '$(artifactDropDirectory)/web-applications/ProjectName.zip'
              enableCustomDeployment: true
              removeAdditionalFilesFlag: true
              xmlTransformation: true
          # ...

An excerpt of the logs of this step/task:

Start tranformation to 'D:\a\_temp\temp_web_package_39967480923393817\Content\D_C\a\1\s\src\ProjectName\obj\Release\Package\PackageTmp\Web.config'.
Source file: 'D:\a\_temp\temp_web_package_39967480923393817\Content\D_C\a\1\s\src\ProjectName\obj\Release\Package\PackageTmp\Web.config'.
Transform  file: 'D:\a\_temp\temp_web_package_39967480923393817\Content\D_C\a\1\s\src\ProjectName\obj\Release\Package\PackageTmp\Web.Release.config'.
Transformation task is using encoding 'System.Text.UTF8Encoding'. Change encoding in source file, or use the 'encoding' parameter if you want to change encoding.

Has somebody experienced this issue as well? Am I doing something wrong or is this a bug or even by design?

I just realized there is a new FileTransform task but I would prefer not using it if it should work in a more simple way.


Solution

  • Setting the variable Release.EnvironmentName solved it and the environment-specific config transformation was triggert. This is possible on the stage-level (in case all jobs share the same environment name) and on the job-level.

    An example:

    # ...
    - stage: TA
      dependsOn: Build
      variables:
        Release.EnvironmentName: TA
      jobs:
      - deployment: TA
        pool:
          vmImage: windows-2019
        environment: 'TA'
        # ...
    

    Answer provided by MSFT on developercommunity.visualstudio.com.