One of the patterns in Continuous Delivery is to “build once, deploy many”. Another is to “deploy the same way to each environment”. This is certainly easier said than done: The 3 biggest challenges in creating a Continuous Delivery pipeline can be summed up as follows:
Below is such an effort at achieving this. The xml I have (lines 1 - 7) are a representation of the notification methods of a SQL Agent Job. But in some environments I may not want to send emails/clutter up event viewer. So at deployment time I should be able to take this xml, update it to what I want it to be, and use the updated version at deploy time, irrespective of what is originally there.
So I take each of the child nodes and check that there is a variable that exists with the identical name of the child node (Test-Path at line 12). If there is I then get the value of this variable and update the inner text of the xml.
Now if you were to take this code and run it now as is, it would fail. Why? The keen-eyed amongst you will notice that I'm checking to make sure that there is for each child node that exists under “notification”, there is a matching variable. To get this to work, you need to add a variable for the other three nodes under “notification”. They are already there, just commented out.