DEV Community

Sanjeevi Subramani
Sanjeevi Subramani

Posted on • Originally published at lkgforit.com on

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

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

https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/file-transform?view=azure-devops

Video Explanation

https://youtu.be/_iPfzH3ENAk

# 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

Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

Referred this issue in GitHub repo hope it helps someone:

https://github.com/MicrosoftDocs/azure-devops-docs/issues/6563

Refer videos in my channel for live explanations.

https://youtu.be/QxJ_y6pV6No

https://youtu.be/dGLWBWZavhw

https://youtu.be/C8t4EUV6yok

YouTube Channel

https://www.youtube.com/channel/UCnYzqHl_und412jN2RTjJVA

Top comments (0)