Search code examples
azure-devopsazure-pipelinesazure-pipelines-release-pipelineazure-pipelines-yamlazure-pipelines-tasks

What are FileTransformTaskV2 Variable substitution rules in Azure Pipelines


I have an Azure DevOps pipeline

pool:
  vmImage: 'windows-latest'

variables:
 System.Debug: true
 one: actual-value
 Two: actual-value
 MappedValue: actual-value

steps:
  - task: FileTransform@2
    displayName: V2 - Transform
    env:
      Three: actual-value
      four: actual-value
      five: $(MappedValue)
      Six: $(MappedValue)
    inputs:
      folderPath: ./
      jsonTargetFiles: settings.json
      xmlTargetFiles: ''
      xmlTransformationRules: ''

  - pwsh: "Get-ChildItem Env:"
 
  - publish: settings.json
    artifact: settings.json

and the following settings.json file

{
    "one":"default",
    "two":"default",
    "three":"default",
    "four":"default",
    "five":"default",
    "six":"default"
}

Now I was hoping that the file transform task will be able to substitute all the value in the settings file but in reality only "one" is replaced.

Few thing to note:

  1. ONE and TWO are set as env variables as seen in the list
  2. Only ONE get replaced in settings.json but TWO does not
  3. Two is define as Pascal case but is lower case in settings file
  4. one and Two both appear in uppercase in env variables listed
  5. Three, four , five and six are mapped to task environment variables
  6. mapped variables also do not get transformed in the settings

So my question is what are the rules for transform task to be able to replace values in settings file? and why only one works and no other one works even they are mapped to env variables all with upper case?


Solution

  • Replacement is done based on the Pipeline Variable, not env variables.

    Take a look on this:

    pool:
      vmImage: 'windows-latest'
    
    variables:
     System.Debug: true
     one: actual-value
     two: actual-value
     MappedValue: actual-value
     three: $(MappedValue)
     four: actual-value
     five: $(MappedValue)
     Six: $(MappedValue)
    
    steps:
      - task: FileTransform@2
        displayName: V2 - Transform
        inputs:
          folderPath: ./
          jsonTargetFiles: settings.json
          xmlTargetFiles: ''
          xmlTransformationRules: ''
    
      - pwsh: "Get-ChildItem Env:"
     
      - publish: settings.json
        artifact: settings.json
    

    and I got:

    {
        "one": "actual-value",
        "two": "actual-value",
        "three": "actual-value",
        "four": "actual-value",
        "five": "actual-value",
        "six": "default"
    }
    

    Beacuse replacement is case sensitive, six was not replaced.