Update appsetting in the Post-deployment script to Project Variable

usability
server
(jxharding) #1

Hi

My question is around updating an appsetting value, in the Post-deployment script section to a Project Variables value?

We have a value that often updates, and I thus can’t do a powershell replace since this value changes.

The pre-deployment script section intentionally removes the web.config file, and thus I cannot update this value there. I can only update this value to the existing web.config that is not included in the deploy.

Thus, how in the post deployment script section could I update the “MyKey” value to Project Variable “MyProjectVariable” (e.g. #{Octopus.Release.Number} )

  <appSettings>
    <add key="MyKey" value="1001" />
  </appSettings>
(Dalmiro Grañas) #3

Hi @jxharding,

Thanks for reaching out!

Octopus’ Variable Replacement feature is executed before the post deployment scripts, so in your case you’ll need to write your own Powershell script to replace the value in your xml config file using something like this: https://stackoverflow.com/a/16429111

Hope that helps,
Dalmiro

(jxharding) #4

Thank you, would i be able to access the Octopus Variables from the post deployment script? e.g. $connectionString = '#{ConnectionString}'

(Dalmiro Grañas) #5

@jxharding from Powershell you’d need to use the variable like this: $connectionString = $OctopusParameters['ConnectionString']

Cheers