azure-pipelines-tasks: FileTransform task not working as expected for appsettings.json file variable substitution

I know how variable substitution works in release pipeline, just check “XML variable substitution” for XML files or write json filename in “JSON variable substitution” textbox. This works well if I’m deploying to “Web App on Windows” app service type. But as soon as I select “Web App on Linux” app service type “File Transforms & Variable Substitution Options” group disappears.

Then I decided to move variable substitution in build pipeline in YAML file (azure-pipelines.yml), that’s where problem started for me.

So, i’m trying to achieve appsettings.json file variable substitution in build pipeline. I already listed variables in library:

image

Here’s the json file:

{
  "Logging": {
    "LogLevel": {
      "Default": "Warning"
    }
  },
  "AllowedHosts": "*",
  "name": "value"
}

Here’s the code i have in azure-pipelines.yml:-

trigger:
 - master

pool:
  vmImage: 'ubuntu-latest'

variables:
  buildConfiguration: 'Release'

steps:
- task: DotNetCoreCLI@2
  displayName: 'Restore project'
  inputs:
    command: 'restore'
    projects: |
      **/WebApplication_Li_CI_CD.csproj
      **/WebApplication_Li_CI_CD_1.csproj
    feedsToUse: 'select'

- task: DotNetCoreCLI@2
  displayName: 'Build project'
  inputs:
    command: 'build'
    projects: |
      **/WebApplication_Li_CI_CD.csproj
      **/WebApplication_Li_CI_CD_1.csproj

- task: DotNetCoreCLI@2
  displayName: 'Publish project'
  inputs:
    command: publish
    projects: |
      **/WebApplication_Li_CI_CD.csproj
      **/WebApplication_Li_CI_CD_1.csproj
    publishWebProjects: True
    arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
    zipAfterPublish: True

- task: CopyFiles@2
  displayName: 'Copy zip files'
  inputs:
    SourceFolder: '$(Build.SourcesDirectory)'
    Contents: '**\*.zip'
    TargetFolder: '$(Build.ArtifactStagingDirectory)'

- task: PublishBuildArtifacts@1
  displayName: 'Publish artifacts'


- task: FileTransform@1
  displayName: 'Update appsettings.json file'
  inputs:
    folderPath: '$(Build.ArtifactStagingDirectory)'
    fileType: 'json'
    targetFiles: '**/appsettings.json'

I tried to adjust folderPath in FileTransformation task, and received errors:

#folderPath: '$(System.DefaultWorkingDirectory)/**/*.zip'
Error: Nopackagefoundwithspecifiedpattern /home/vsts/work/1/s/**/*.zip

#folderPath: '$(System.DefaultWorkingDirectory)/_WebApplication_Linux_CI_CD/drop/WebApplication_Li_CI_CD.zip'
Error: Nopackagefoundwithspecifiedpattern /home/vsts/work/1/s/_WebApplication_Linux_CI_CD/drop/WebApplication_Li_CI_CD.zip

#folderPath: '$(Build.ArtifactStagingDirectory)/**/*.zip'
Error: More than one package matched with specified pattern: /home/vsts/work/1/a/**/*.zip. Please restrain the search pattern.

#folderPath: '$(Build.ArtifactStagingDirectory)/**/WebApplication_Linux_CI_CD.zip'
Error: Nopackagefoundwithspecifiedpattern /home/vsts/work/1/a/**/WebApplication_Linux_CI_CD.zip

#folderPath: '$(Build.ArtifactStagingDirectory)/_WebApplication_Linux_CI_CD/drop/WebApplication_Li_CI_CD.zip'
Error: Nopackagefoundwithspecifiedpattern /home/vsts/work/1/a/_WebApplication_Linux_CI_CD/drop/WebApplication_Li_CI_CD.zip

#folderPath: '$(Build.ArtifactStagingDirectory)/WebApplication_Linux_CI_CD.zip'
Error: Nopackagefoundwithspecifiedpattern /home/vsts/work/1/a/WebApplication_Linux_CI_CD.zip

#folderPath: '$(Build.ArtifactStagingDirectory)/drop/WebApplication_Linux_CI_CD.zip'
Error: Nopackagefoundwithspecifiedpattern /home/vsts/work/1/a/drop/WebApplication_Linux_CI_CD.zip

#folderPath: '$(Build.ArtifactStagingDirectory)/drop/**/WebApplication_Linux_CI_CD.zip'
Error: Nopackagefoundwithspecifiedpattern /home/vsts/work/1/a/drop/**/WebApplication_Linux_CI_CD.zip

And none of the combination works for me.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 20 (9 by maintainers)

Most upvoted comments

@itorian I am sorry for the delay in response. I just tried to run the task and I was able to do that successfully. Sharing the YAML script and a few points due to which the issue could be occurring. YAML snippet:

steps:
- task: FileTransform@1
  displayName: 'Update appsettings.json file'
  inputs:
    folderPath: '$(System.DefaultWorkingDirectory)/_adcf/Application.zip'
    fileType: json
    targetFiles: Application/appsettings.json

My folder format:

- Application.zip
    - appsettings.json
    - ...

Can you tell me if this was of any help?

So basically the project path should be: $(System.DefaultWorkingDirectory)/{your_project_name}/{your_zip_folder_name}

I followed the same steps. In the log, i see the values substituted in appsetting.json however i do not see the new values in the appsettings under artifact. Any thoughts.

@mliesmons Built-in variables are excluded in JSON variable substitution. 62449643-4ace9a80-b788-11e9-842d-5738608f6cfc

We exclude such variables that have the same prefix as pre-defined variables.

Reference: https://github.com/microsoft/azure-pipelines-tasks/blob/e6b2859cadd9e69b964dbb5b425720b7172d1abf/Tasks/Common/webdeployment-common-v2/variableutility.ts#L3

@itorian Hi, Azure App Service deploy does not support Variable Substitution for Linux apps. Also, we have deprecated that functionality in the task. We have a new task: File Transformation (https://github.com/microsoft/azure-pipelines-tasks/tree/master/Tasks/FileTransformV2) for file transformation and variable substitution now which works with all app types since it takes a package as it’s input. As for your query, I will check the file path error and get back to you.

Hi Arora, There is still a bug in the new FileTransform. I was already worried to see in the log only the leaf keys, and not the full hierarchy of which key is being replaced. I have the key ApiKey twice in my JSON but in a different hierarchy. This fails, the last ApiKey found is replaced with its current value, a noop in fact. Another key, with the same parent, is simply not logged/replaced, no clue why. Honestly, I am wasting precious time on what should be a simple task… Michel.

@itorian Hi, Azure App Service deploy does not support Variable Substitution for Linux apps. Also, we have deprecated that functionality in the task. We have a new task: File Transformation (https://github.com/microsoft/azure-pipelines-tasks/tree/master/Tasks/FileTransformV2) for file transformation and variable substitution now which works with all app types since it takes a package as it’s input. As for your query, I will check the file path error and get back to you.