How to use output variable for replacing variables in config file

Hi.

I think this question pretty much resembles my question, but the code part is missing from the question. Can somebody help here?

Best regards,
Nikola.

Hi Nikola,

Thanks for getting in touch! I’m sorry about the confusion on that thread. It was created in our old forum and obviously didn’t migrate the code block when we switched to the new forum. You can view the entire content here.

https://help.octopusdeploy.com/discussions/questions/11529-configfile-variable-substitution-using-task-output-variables

What they did was use output variable substitution syntax in their config file: #{Octopus.Action[StepName].Output.VariableName} which grabs VariableName that was created in StepName.

I hope this helps! Let me know how you go or if you have any further questions moving forward. :slight_smile:

Best regards,

Kenny

Hi Kenny,

Thank You for reply. I have tried to use #{Octopus.Action[StepName].Output.VariableName}, but with no luck.

Let me broaden a question a little. Here is the part of Web.config file (updated with suggestion from previous answer):

<appSettings>
    <add key="Password" value="#{Octopus.Action[GeneratePassword].Output.Password}" />    
  </appSettings>

First step in Octopus Deploy is executing power shell script called GeneratePassword and looks like this:

[Reflection.Assembly]::LoadWithPartialName("System.Web")
$pwd = [System.Web.Security.Membership]::GeneratePassword(15,2)
Set-OctopusVariable -name "Password" -value $pwd -sensitive

Second step is IIS deploy. Both Replace appSettings and connectionString entries in any .config files and Automatically run configuration transformation files are checked.

I have tried to use xdt:Transform="SetAttributes" xdt:Locator="Match(key)" in config file (Web.config), but that required importing xdt namespace, which in turn caused error when deployed (server is not working, this is error: Parser Error Message: Unrecognized attribute 'xmlns:xdt'. Note that attribute names are case-sensitive.). I had also tried to use those attributes in Web.QA.config, but they are not applied. What am I doing wrong?

Best regards,
Nikola.

Hi Kenny,

I’ve managed to solve the issue myself at the end. What I did, I had defined a variable in the project like Password -> #{Octopus.Action[GeneratePassword].Output.Password]. After setting this, value in config file is correctly replaced. Thanks for help.

Best regards,
Nikola.

Hi Nikola,

That’s great to hear you’ve found the solution! Thank you for letting me know the outcome, and please don’t hesitate to reach out if you have any further questions or concerns moving forward. :slight_smile:

Best regards,

Kenny

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.