Search code examples
azureazure-devopsazure-pipelinesdevopsvariable-substitution

Azure Devops Release Pipeline XML Variable Substitution not working


I have a very simple variable substitution in my release pipeline, but it's not working. I have the variable in the connectionStrings.config file as such:

<?xml version="1.0"?>
<connectionStrings>
  <add name="ExpenseDBConnectionString" connectionString="__ProdConnString__" providerName="System.Data.SqlClient" />
</connectionStrings>

I then have the variable defined in the release pipeline:

enter image description here

I also have the XML Variable Substitution enabled in the Deploy Task:

enter image description here

But I run the release, and the variable doesn't get substituted. I get this message in the logs:

2020-02-28T19:57:26.1262198Z Initiated variable substitution in config file : D:\a\_temp\temp_web_package_875508750741006\Content\D_C\a\1\s\Expenses.Web\obj\Release\Package\PackageTmp\App_Config\ConnectionStrings.config
2020-02-28T19:57:26.1312311Z Processing substitution for xml node : connectionStrings
2020-02-28T19:57:26.1321602Z Skipped Updating file: D:\a\_temp\temp_web_package_875508750741006\Content\D_C\a\1\s\Expenses.Web\obj\Release\Package\PackageTmp\App_Config\ConnectionStrings.config

This should be pretty simple, so not sure what setting I am missing. Help!


Solution

  • You should define your variable name as ExpenseDBConnectionString in the release pipeline. Below is the description of the setting XML variable substitution. The variables are matched against the key or name entries

    Variables defined in the build or release pipeline will be matched against the 'key' or 'name' entries in the appSettings, applicationSettings, and connectionStrings sections of any config file and parameters.xml. Variable Substitution is run after config transforms.

    So the variable defined should be like below:

    enter image description here

    Below screenshot is the result from my test release, you can see the connectionString was replaced.

    enter image description here

    For more information about XML variable substitution, please check it out here.

    There are also some third party substitution tools(ie. Magic Chunks) that you can use to replace your config settings. Please check out the example for this thread.