Octopus Deploy Tutorials: Transform XML file using Structured configuration variables


How it works?

For XML files, the values to replace are located using the standard XPath syntax. Octopus supports both XPath 1 and XPath 2.

Octopus variables with names that are valid XPath expressions are matched against the target XML files. For example, if you have a variable called //environment with the value production, it will replace the contents of all elements with production.

Read – https://www.w3schools.com/xml/xpath_syntax.asp

Step 1 – To enable Structured Configuration Variables on a step that supports the feature, click the CONFIGURE FEATURES link, select Structured Configuration Variables, then click OK.

Step 2 – In the Structured Configuration Variables section of the step, specify the relative paths to your structured configuration files, relative to the working directory. For instance:


Replacing content

When replacing content, the replacement can only be as rich as what was originally there. If you select an element that contains only text, the replacement will be treated as text and structure-defining characters will be encoded as entity references. However, if you select an element that contains further element structures, the replacement is treated as an XML fragment, and structure-defining characters will be added as is.

This means that if you replace a password or connection string, any characters like &< and > will be safely encoded within the string. For example, assume the target file contains the following:

Rajesh Kumar
Follow me
Latest posts by Rajesh Kumar (see all)
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x