Im using AzureDevops for my pipelines using Powershell as scripting option.
During the steps i read secrets from Hashicorp Vault and load them as env Vars. that way i can use them by addressing : $(secret1)
These secrets will be inserted into a web.config file at the specific elements, each secret has its own placeholder, secret env var name is matching each elements' name field in the web.config
web.config fragment:
<connectionStrings>
<add name="ServiceBusConnectionString"
connectionString=""
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
<add name="Hc24DbConnectionString"
connectionString=""
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
<add name="CacheStorageConnectionString"
connectionString=""
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
<add name="AzureStorageConnectionString"
connectionString=""
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
<add name="EmulatorConnectionString"
connectionString=""
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
<add name="MongoDbConnectionString"
connectionString=""
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
the value of "connectionString" would be replaced according to connectionStrings.add.name
Im trying to achieve that with this Powershell logic:
$names = $xmlObject.configuration.connectionStrings.add.name
$($name)
foreach ($name in $names)
{
Write-Host "name is $name"
$connectionstring = $xmlObject.configuration.connectionStrings.add | ?{$_.name -eq $name}
Write-Host "Connection String name is"$connectionstring.connectionString
Write-host "Name ENV var is :" "`$($name)"
$xmlObject.Save('Web.$(Release.EnvironmentName).config')
}
Currently im not able to get the value of the secret, but only the name of the variable.
F.E, my Write-Host will get me: Name ENV var is : $(ServiceBusConnectionString)
Any ideas what i may be missing ?
Write-Host "Connection String name is"isn't outputting what you expect? In your example, those are empty so the result would be empty (but maybe that's because you redacted them in your post). And how are you expecting to get the values of the credentials into this script? I don't see anything that's doing that.