question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FileTransform task not working as expected for appsettings.json file variable substitution

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:20 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
SaraJonnascommented, Jun 3, 2021

@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.

1reaction
eaarora-mscommented, Jan 4, 2020

@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

Read more comments on GitHub >

github_iconTop Results From Across the Web

File transform task not substituting all variables and ...
We use File transform task in replacing values of our config file. We noticed recently that the file transform task is not working...
Read more >
.net - JSON variable substitution in appsettings.json file is not ...
This feature substitutes values in the JSON configuration files. It overrides the values in the specified JSON configuration files (for ...
Read more >
FileTransform@2 - File transform v2 task - Microsoft Learn
Variable substitutions are run after config file transformations. Variable substitution is applied for only the JSON keys predefined in the ...
Read more >
Azure Pipelines – Parameters + JSON File Substitution
Azure Pipelines provides a FileTransform Task for variable substitution in configuration files, so given an appsettings file like this: ...
Read more >
Wrestling with Azure DevOps Pipelines - ITWriting.com
I had many issues. The main documentation on variable substitution is here. This is terrible. Note that if you look at the YAML...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found