Environment-specific configuration

How can I add either a custom MSBuild task (to do a config transformation) or add a powershell scriptlet do the same thing so that it executes at deploy time and can use a variable that somehow contains the environment name? I can’t necessarily rely on hostname since the list of hosts in each environment may change.

Octopus does this for you automatically: https://octopus.atlassian.net/wiki/display/help/Variables

That’s awesome. Can I request that it start with a “web.base.config” before the config file transformations? that’s what we’re basically using now.

Well, it kind of does that. :slight_smile: When you deploy Octopus will run web.Release.config and then run web..config. So, basically you just need a web.config that matches the name of each of your environments and then a web.Release.config to serve as the “base” that you described.

hmmm… looks like the forum ate part of my formatting. That should be web.[EnvironmentName].config instead of web…config

But that’s where both “web.Release.config” and “web.Environment.config” are both transformation files, right? they’re both applied to “web.config” directly? The documentation isn’t clear about which are config files and which are transforms.

Yes, they are both transform files that will be applied to your web.config.

Is there a variable to override this?

We have 5 QA environments but the transform is the same so we’d like to continue to use web.qa.config vs web.qa[1-5].config.

I don’t know of a way to override that (except for overriding the OctopusEnvironmentName variable which I expect would have some undesired consequences). Since all of the transforms are the same I’d recommend that you keep them in a web.qa.config file and then have your build process copy that to web.qa[1-5].config files before the octopus package is created. That way you only have to maintain them in one file but it will always adapt to which ever QA environment you are deploying to. Here’s an msbuild task for it:

<Target Name="CopyQAConfig">
  <Copy SourceFiles="web.qa.config" DestinationFiles="web.qa1.config;web.qa2.config;web.qa3.config;web.qa4.config;web.qa5.config" />
</Target>

Oof that’s dirty. If my boss saw me hard code that - I’m dead.

Any chance we could put support for specifying what file to transform on the backlog?

I agree this would be a nice feature to have and hopefully they will add it to the backlog. I have 4 dev and 4 staging environments and this would be really helpful.

Thanks for the suggestion Bill and jfrench, I’ve added it to the backlog:

https://trello.com/board/octopus/4e907de70880ba000079b75c

Paul