Kalpesh Bhadra
Kalpesh Bhadra

Reputation: 450

Azure replace token for Service model endpoint for Asp.net MVC in pipeline release task

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

Upvotes: 1

Views: 870

Answers (2)

Kalpesh Bhadra
Kalpesh Bhadra

Reputation: 450

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.

Upvotes: 0

Krzysztof Madej
Krzysztof Madej

Reputation: 40829

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.

Upvotes: 0

Related Questions