Applying custom settings with Octopus Deploy
If you’re a .Net developer and not currently doing automated deployments then you really should be. If you’d like some help getting started send me a message in the comments and I’ll drop you an email.
The core of any deployment is the ability to easily manage and apply configuration values, across environments and across your different apps/web apps.
Octopus Deploy has first class support for managing variables, including setting different scopes or environments and steps in your deployment process. It also has first class support for substituting variables into your
So what’s the problem?
The trouble comes when you start using custom settings in your app.config and web.config files. For example, you might have a web.config file that looks like this:
Octopus Deploy does have a built in way of dealing with this problem, but the downside is that you have to hard-code the values in the Octopus Deploy convention, e.g.
The problem that I have with the above is when I want to hard-code the values for local development. One of the applications I work on has a config item called BaseUri and when I’m working locally I like to have it set to my local machine e.g. http://localhost:44301. So the syntax above doesn’t work unless I’m happy with constantly changing the values.
In this blog post I’m going to show how with a little bit of PowerShell we can update the custom settings shown above.
PowerShell makes your deployments awesome, especially in the context of Octopus Deploy. Anything that isn’t baked in can easily be implement with a little bit of PowerShell.
This script does the following:
- Line 1-4: Finds the config file and then loads it as an XML object
- Line 6: Using XPath looks for the node with the custom configuration
- Line 8-14: If the node was found, updates the values of the custom keys, and then saves the file.
Go forth and automate.