A.G.
A.G.

Reputation: 334

How to set Azure release pipeline release name in azure app service appsettings.json

I need to set the Azure pipeline release name to an Azure app service appsettings.json file for the application to display. I am using the release pipeline classic. I know there is a default variable called "Release.ReleaseName" in the pipeline. How to set its value to the application appsettings.json before deployment?

Release.ReleaseName - Example: Release-47

Upvotes: 0

Views: 614

Answers (1)

Fairy Xu
Fairy Xu

Reputation: 568

You could use the Replace Token task from Replace Tokens Extension.

Here are my steps, you could refer to them:

Json file:

{
  "Position": {
    "Title": "Editor",
    "Name": "xx"
  },
  "MyKey":  "#{Release.ReleaseName}#",
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*"
}

Replace Token task sample:

- task: replacetokens@3
  inputs:
    rootDirectory: 'Folder Path'
    targetFiles: '**/appsettings.json'
    encoding: 'auto'
    writeBOM: true
    actionOnMissing: 'warn'
    keepToken: false
    tokenPrefix: '#{'
    tokenSuffix: '}#'
    useLegacyPattern: false
    enableTelemetry: true

Then the variables in Appsettings.json will be replaced.

Upvotes: 1

Related Questions