Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
}
like image 359
Rabadash8820 Avatar asked Sep 28 '17 18:09

Rabadash8820


People also ask

How do I pass a variable from one task to another in Azure DevOps?

Share variables between Tasks across the Jobs (of the same Stage) We need to use the isOutput=true flag when you desire to use the variable in another Task located in another Job.

How do you use a variable group in a release pipeline?

To use a variable group, open your pipeline. Select Variables > Variable groups, and then choose Link variable group. In a build pipeline, you see a list of available groups. In a release pipeline, for example, you also see a drop-down list of stages in the pipeline.


2 Answers

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

like image 183
Eddie Chen - MSFT Avatar answered Oct 07 '22 07:10

Eddie Chen - MSFT


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

like image 45
Humberto Rodrigues Avatar answered Oct 07 '22 05:10

Humberto Rodrigues