8

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
}
Rabadash8820
  • 2,328
  • 3
  • 27
  • 49
  • Do you means substitute the json variable in **Azure App Service Deploy task**? It only support user definied variable with the name `Release.DefinitionName`. – Marina Liu Sep 29 '17 at 06:29
  • The variable `Release.DefinitionName` is the user defined variable which should match your appsettings.json file. (the parameter `Release` and `DefinitionName` are what you showed in your example `appsettings.json` file. – Marina Liu Oct 02 '17 at 06:17
  • @Marina-MSFT No I am using the basic **IIS Web App Deploy** task – Rabadash8820 Oct 02 '17 at 16:10

2 Answers2

12

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

Eddie Chen - MSFT
  • 29,708
  • 2
  • 46
  • 60
  • Wowww, I feel foolish for missing that note... I also forgot that you can use the `$()` syntax to use Default variables in a Custom variable. Thank you very much for pointing out my user error and providing this simple fix! – Rabadash8820 Oct 02 '17 at 16:14
  • A simple fix that is basically a workaround for what looks like a bug/not-implemented yet.*why* can't you use release variables at environment level. I basically need to replicate the *same* variable 'x' times pointed to the release variable. "expected behaviour?" - that's garbage. Could I add a disclaimer to my site "sorry it doesn't work logically,it's expected behaviour though so that's just tough". VSTS release manager is *very* poor compared to the alternatives out there - it's just easy as it's all integrated. – GrahamB Dec 03 '17 at 11:04
  • @GrahamB I agree; one would definitely expect default variables to work like custom variables out of the box. Even worse, it looks like [someone else](https://visualstudio.uservoice.com/forums/330519-visual-studio-team-services/suggestions/11355081-vsts-release-variables-across-enviroments) has already raised your issue on the VSTS suggestions forum, and it got declined. :/ – Rabadash8820 Dec 04 '17 at 17:25
7

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

stimms
  • 42,945
  • 30
  • 96
  • 149