1

There are 10+ project in my solution. One project has config, name Variable.release.config file which has all the application variable, connection string and other web.config's module which needs to replaced with Azure variable from Library. This config file is used by all the project. The solution has Asp.net MVC website which has it's own web.config, web.release.config. I am trying to xml transform variable from Variable.release.config, It is transforming everything in web.config but value of endpoint variable in client section of endpoint address is not getting replaced.

Previously I was using Azure App Service Deploy and following is its YAML:

steps:

    - task: AzureRmWebAppDeployment@4
      displayName: 'Azure App Service Deploy: abc-tst'
      inputs:
        azureSubscription: 'ABC Technologies(XXXX-XXX-XXX-XXX-XXXXXX)'
        WebAppName: 'ABC-tst'
        deployToSlotOrASE: true
        ResourceGroupName: 'abc-tst'
        SlotName: T2
        packageForLinux: '$(System.DefaultWorkingDirectory)/$(Release.DefinitionName)/drop/ABC.Frontend.zip'
        enableXmlTransform: true
        enableXmlVariableSubstitution: true

It was not replacing variable in endpoints. I came across several article that says only endpoint can not be replaced with xml transformation I need to use 3rd party tools to transfer Replace Token

I tried with following steps:

  1. File transform
  2. Replace Token
  3. Azure App Service Deploy

But it didnt replaced endpoint variable address in web.config though it xml transformed was success and in logs Replace token has replaced the token of that variable.

After that I modified my release task as given in bellow image after reading this answer.

Is there any way to replace variable value in endpoint address or am I missing anything?

Azure release pipeline task

Kalpesh Bhadra
  • 406
  • 1
  • 6
  • 17

2 Answers2

0

Are you sure you have all configured as it should be?

I tried this replace token in release pipeline and all went fine. Are you sure you have traget files properly configured?

Do you have such output in logs?

2020-05-28T07:11:02.8850410Z replacing tokens in: D:\a\r1\a\repos\stackoverflow\38-endpoint-replace\Web.config
2020-05-28T07:11:02.9045428Z   1 tokens replaced out of 1
2020-05-28T07:11:02.9048164Z replaced 1 tokens out of 1 in 1 file(s) in 0.079 seconds.

Please try to add such powershell step to check file content before and after replace token step.

enter image description here

Note

Be aware that that my last advice my cause to keep this in logs. If you have sensitive data please revoke them after or remove from file for test purpose.

Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107
  • Are those steps for Build Pipeline? I need to use variable substitution/replacement at the time of release. – Kalpesh Bhadra May 28 '20 at 05:03
  • @KalpeshBhadra Sorry, you are right. I checked now for release pipeline and there is not reason why it can't work. Please check my edit. – Krzysztof Madej May 28 '20 at 07:20
  • Yes I get such logs which says 2 token replaced out of 3. And it showed waning for which token didnt got replaced. – Kalpesh Bhadra May 28 '20 at 10:58
  • Here is the warning. 2020-05-26T17:37:14.9560115Z replacing tokens in: C:\Agent1\_work\r3\a\ABC\files\Content\C_C\Agent1\_work\686\s\DotNetSystem\ABC.CRM.MVC\Frontend\obj\Release\Package\PackageTmp\Web.config 2020-05-26T17:37:14.9578263Z ##[warning] variable not found: SvcRefAccDetailsByRefV2.AAgetAccountDetailsViaReferenceV2Port 2020-05-26T17:37:14.9592671Z 2 tokens replaced out of 3 – Kalpesh Bhadra May 28 '20 at 12:09
  • This simply means that there is no variable with this name. Are you sure that you have it in your pipeline? – Krzysztof Madej May 28 '20 at 12:11
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/214824/discussion-between-kalpesh-bhadra-and-krzysztof-madej). – Kalpesh Bhadra May 28 '20 at 12:12
0

I tried with many azure task by extracting file then transforming it and again zip it to the same location. But nothing worked. I removed all the task and just kept one task of "Azure App Service Deploy" with following YAML:

enter image description here

I had modified my we.release.config endpoint with following:

<endpoint address="#{variable1}"  binding="basicHttpBinding" bindingConfiguration="TransPortCertificateBinding" contract="Contract1" name="Service1"
                xdt:Transform="SetAttributes" xdt:Locator="Match(address)"/>

Previously the Match was applied on contract which failed to transform the value from library variable.

Kalpesh Bhadra
  • 406
  • 1
  • 6
  • 17