I've got the following powershell code that updates xml nodes with values from Octopus Deploy.
foreach($key in $OctopusParameters.Keys)
{
$myXPath = "$nodeXPath/$($key.Replace(".", "/"))"
try{
$node = $doc.SelectSingleNode($myXPath)
} catch { <# sometimes Octopus passes in crappy data #> }
if($node){
Write-Host "Overriding node: '$key'`t`t With value: $($OctopusParameters["$key"])"
$node.'#text' = $OctopusParameters["$key"]
}
}
It's working great, but only if the original xml node has a value.
<something>Replaced_by_octopus</something> <!-- I work -->
<something></something> <!-- I fail -->
The failure is on the line $node.'#text' = $OctopusParameters["$key"]
with the following error message
Get-EnvironmentSettings : Exception setting "#text": "The property '#text' cannot be found on this object. Verify that the property exists and can be set."
What do I need to do to be able to update that node regardless of if it's empty or not?