I am using variable name called “LoginPassword” in project variable which I have marked as sensitive.
I am using powershell script step to update the confi.xml by referring #{LoginPassword} on place holder in below powershell script which is not working and throwing following error :
It looks like the “LoginPassword” variable name is being used twice - there’s the one from within Octopus Deploy and there is one created from $node.Password. I’d recommend changing the second one to have a different name.
It may be worth noting that the “Write-Host $LoginPassword” line should only display “******” in the task logs, as Octopus Deploy will attempt to censor sensitive variables.
Could you please try the change above and advise what error message you see (if any)?
Actually, you were right at your suggestion. It’s working fine and the only culprit is that I am not saving the xml after writing the password to file.
Thanks for the Support
Final PowerShell Code
#Create Functions To Load & Save Target XML Config Files
function LoadXML ($pathtoXML) {
$script:xmlFile = "$pathtoXML"
$script:xml = New-Object xml
$xml.psbase.PreserveWhitespace = $true
$xml.Load($xmlFile)
}
function SaveXML {
$xml.Save($script:xmlFile)
}
$XMLPath = "C:\Support\Config.xml"
LoadXML -pathtoXML "$XMLPath"
$xpath = "/Configuration/Data/Section/Item[@Name='SeatInformation']"
$node = $xml.SelectSingleNode($xpath)
$node.Password = "${LoginPassword}"
SaveXML