Config transforms - RemoveIfExists?

Hi,

I just downloaded Octopus Deploy and tried to get it working with our existing deployment configuration.

As part of this configuration we use XML config transforms. One of the transforms removes the defaultProxy from system.net in web.config - if present. This was added to not mistakenly deploy an application that a developer used Fiddler to troubleshoot.
This worked fine with a standard xdt:Transform=“Remove”.

However, when using the built-in XML config transformation support in Octopus Deploy we get an error:
No element in the source document matches ‘/configuration/system.net/defaultProxy’

How do I tell Octopus Deploy to only remove the element if it is present? (I know I can configure Octopus Deploy to treat config transform errors as warnings - but I’d rather fix the problem)

As a follow-up…

I tried adding Octopus.Action.Package.IgnoreConfigTransformationErrors=True to the Project Variables, but I still get the same error :frowning:

Regarding my last comment…

It seems you have to create a new release (and not just retrying an existing one) in order for the updated Project Variables to be used.

Still got the question about RemoveIfExists though :wink:

Hi Johan,

Thanks for getting in touch! The XML Config Transformation we do as part of your deployment is just good old XML Config Transformation, we don’t really do anything special except make sure the debugging information from the transform process ends up in your logs.

Based on my research today, Microsoft has recently added InsertIfMissing but there is no mention of RemoveIfExists. From the testing I’ve done today, Remove and RemoveAll behave the same way: if it cannot find a matching element to remove, it writes the warning to the log.

The best options I can recommend at the moment are to:

  • Only add the xdt:Transform="Remove" where the element will actually exist in the source file.
  • Use Octopus.Action.Package.IgnoreConfigTransformationErrors=True like you mentioned, remembering you can scope that value to the specific step that is misbehaving to limit exposure.

Hope that helps!
Mike

The following looks slightly awkward at first glance but is a way in XDT that cleanly (ie, no warnings) ensures that an element is removed whether it existed or not.

As there are no warnings when doing it this way, it works without having to resort to ignoring errors/warnings in Octopus.

To ensure that foo is removed:

<foo xdt:Transform="InsertIfMissing" />
<foo xdt:Transform="Remove" />

IMO, this is the preferable solution with the limited tools we have available in XDT.

2 Likes

Hi Hakan,

That’s a cool idea. Thanks for posting!

Mike