FileTransform task not working as expected for appsettings.json file variable substitution
See original GitHub issueI 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:
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:
- Created 4 years ago
- Comments:20 (9 by maintainers)
Top GitHub Comments
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.
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