File Transformation (variable substitution) and issues faced in Azure Devops  -  YAML

Variable substitution in Azure Devops | File Transformation in azure devops using YAML | Troubleshooting File Transformation in Azure Devops

Sanjeevi Subramani's photo
Sanjeevi Subramani
·Mar 9, 2021·

1 min read

File Transformation (variable substitution) and issues faced in Azure Devops  -  YAML

Subscribe to our newsletter and never miss any upcoming articles

Play this article

Following this document used file transformation task in Azure Devops to substitute variables in json and xml files:

Video Explanation

# File transform
# Replace tokens with variable values in XML or JSON configuration files
- task: FileTransform@1
 inputs:
 #folderPath: ‘$(System.DefaultWorkingDirectory)/**/*.zip’ 
 #enableXmlTransform: # Optional
 #xmlTransformationRules: ‘-transform **\*.Release.config -xml **\*.config-transform **\*.$(Environment.Name).config -xml **\*.config’ # Optional
 #fileType: # Optional. Options: xml, json
 #targetFiles: # Optional

When using this you will get following error message: “changes already present message”.

Got the changes already present message when directly targeting the source folder. The idea is that the build package is edited by this task, so configuration is updated before test or deployment.

This worked for me (note the **/):

steps:

task: FileTransform@1
displayName: ‘File Transform: appsettings.json’
inputs:
folderPath: ‘$(System.DefaultWorkingDirectory)’
fileType: json
targetFiles: ‘**/appsettings.json’

To prevent another error that will be experienced if doing variable substitution for non-windows app : “Cannot perform XML transformations on a non-Windows platform”

you need to specify an empty xmlTransformationRules. This works against a Linux app service:

task: FileTransform@2
  inputs:
    folderPath: $(Pipeline.Workspace)/path-to/my-package.zip
    jsonTargetFiles: appsettings.json
    xmlTransformationRules: '' # disabled

Referred this issue in GitHub repo — hope it helps someone:

Refer videos in my channel for live explanations.

YouTube Channel

 
Share this