0
votes

I have a web.config file that has the following elements:

<client>
 <endpoint address="url_1" />
 <endpoint address="url_2" />
 <endpoint address="url_3" />
</client>

Now, I want to change it depending on the environment that I am deploying to. I have created a release pipeline that deploys to my dev and prod environment on Azure, I am using XML Variable Substitution to change whatever variables I need such as connectionString in my prod environment.

I want to change the 3 endpoint elements contents in the web.config file in my PROD environment as well.

For instance, it shoud look like this in the respective environments:

DEV:

<client>
 <endpoint address="url_1" />
 <endpoint address="url_2" />
 <endpoint address="url_3" />
</client>

PROD:

<client>
 <endpoint address="url_4" />
 <endpoint address="url_5" />
 <endpoint address="url_6" />
</client>

I looked into XML File Transformation, and I don't want to add onto the file. I want to remove url_1, url_2, url_3 and replace them with url_4, url_5, url_6

Is there a way on the release pipeline to accomplish this task without breaking the variable substitutions that I have added in place?

2

2 Answers

0
votes

According to your description, if you want to change the multiple XML element contents during running the pipeline, I recommend that you use the extension task Magic Chunks. This task can transform configuration files during the build process.

You can install Magic Chunks task to your organization, then add it to your pipeline. It tested your web.config with below example settings for magic chunk task: enter image description here

Regarding the parameters Path and transformations: You need to specify your own configuration file path and required transformations.

Below is my test, you can refer to it: enter image description here enter image description here

After the pipeline runs successfully, we check the artifact file and find that the elements in the config file have changed. enter image description here

0
votes

You can use Replace tokens task to achieve this. Note that you will have to save these variable values in the pipeline/Variable group. For eg: Value of url1 will be url_1 scoped to Dev Stage.

XML file setup:

<client>
 <endpoint address="#{url1}#" />
 <endpoint address="#{url2}#" />
 <endpoint address="#{url3}#" />
</client>

Result:

Dev:

<client>
 <endpoint address="url_1" />
 <endpoint address="url_2" />
 <endpoint address="url_3" />
</client>

Prod:

<client>
 <endpoint address="url_4" />
 <endpoint address="url_5" />
 <endpoint address="url_6" />
</client>