I’m trying to update my json file using FileTransform@2 by using variables from the Azure DevOps Library to populate these, but I am just getting an error that the value is already there.
##[error]Failed to apply JSON variable substitution. Changes are already present in the package.
This is part of my YAML file:
stages:
- stage: UpdateSettingsFile
displayName: 'Update settings file with ADO values'
jobs:
- job: UpdateSettings
steps:
- task: FileTransform@2
displayName: 'Transform JSON Configuration'
inputs:
folderPath: '**/'
fileType: 'json'
jsonTargetFiles: '**/${{ parameters.powerPlatformEnvironment }}-deployment-settings.json'
JSONVariableSubstitution: true
Overwrite: true # Overwrite the existing file
and this is an example of my .json file
{
"EnvironmentVariables": [
{
"SchemaName": "firstEmail",
"Value": "$(firstEmail)"
}
]
}
Should the value be left blank? How can i get around this?
The values should be updating in the .json file to import to Power Platform
2
Answers
You can use extension Replace Tokens, which can replace tokens in text based files with variable value. For example,
my.json:
YAML file:
Variable Group:
Result:
The reason of the issue is that you defined the variable with wrong name. To use the FileTransform@2 task to perform variable substitution in JSON file, you need to must define the variable using
JSONPath
expressions.See below example as reference:
The sample of JSON file (config.json). And want to use the FileTransform@2 task to replace "
[email protected]
" and "[email protected]
" with two new values.The sample of pipeline main YAML (azure-pipelines.yml).
The result.
Related documentations: