Rabadash8820
Rabadash8820

Reputation: 2554

VSTS JSON Variable Substitution with Default Release Variables

TL; DR

Is there any way that I can use JSON variable substitution with default Release variables in VSTS?

Description

With VSTS, I can use JSON variable substitution to set values in an appsettings.json file at release time. For example, with an appsettings.json file that looks like this:

{    
  "ConnectionStrings": {
    "DM_ADJ": "placeholder",
    "DM_SALES": "placeholder"
  },
  // And so on.  Placeholders get replaced
}

I can define a Release variable in VSTS called ConnectionStrings.DM_ADJ, and the value I provide there will replace "placeholder" in the corresponding JSON line.

Now, I would also like to use some of the default Release variables in my app's configuration. For example, there are default Release variables called Release.DefinitionName and Release.DefinitionId. I thought that I could substitute them into an appsettings.json config section like below, but unfortunately, when the Release completes, the "placeholder" strings do not get replaced. Am I missing something?

{
  "Release": {
    "DefinitionName": "placeholder",
    "DefinitionId": "placeholder",
  }
  // And so on.  Placeholders do not get replaced
}

Upvotes: 8

Views: 10028

Answers (2)

Humberto Rodrigues
Humberto Rodrigues

Reputation: 179

you need to specify the json file you want to change the values

Release Pipeline

then you just need to create a variable with the path you want to change. for example i want to change the property Version

Json File

so, i need to create a variable with this name:

Aplicacao.Version

Variables

Upvotes: 7

Eddie Chen - MSFT
Eddie Chen - MSFT

Reputation: 29976

This is an expected behavior since it excludes the build/release's system definition variables: enter image description here

If you want to use the system definition variables in the json file, creating a custom variable and set the value to system defined variable like following instead of using system defined variable directly: enter image description here

Upvotes: 12

Related Questions