Use the same transform file for 2 environments

Hi,

I have ‘Stage’ and ‘Prod’ environments. I have Web.Prod.config transform file.

Is there a way to make a ‘Stage’ deployment use the Web.Prod.config transform?

I prefer not having to copy Web.Prod.config into a file named Web.Stage.config (obviously that would work).

Thank you,

Hi,

Thanks for getting in touch! In Octopus, you have a couple of options in regards to automatically naming your Web.config based on environment. The answer is to use a variable in the naming of your Web.config, there are a couple of options for doing this. I’ll cover them below.

The first option would be to use one of the Octopus system variables and have Octopus automatically substitute it during the deployment. The system variable used by Octopus to store the current environment is: #{Octopus.Environment.Name}. So you could use Web.#{Octopus.Environment.Name}.config, which upon deploying to the Prod environment would evaluate to Web.Prod.config.

Here is a link to the system variables section of our documentation if you would like to look more into it. https://octopus.com/docs/deploying-applications/variables/system-variables

The second option you have would be to create your own variable, for example ConfigEnvironmentName. This Variable could be created multiple times and given different values, say one for each environment. You could then scope each variable to its respective environment.
Then when you configure your configuration files in Octopus you could define Web.#{ConfigEnvironmentName}.config. This variable will evaluate to whatever value you have set per the scope. (See Screenshot1.jpg for an example)

I have provided a link to our Scoping Variables documentation page if you would like to look more into scoping variables in Octopus.

I hope that helps answer your question and get you a bit more automated. :slight_smile:
Let me know if you have any further questions or if you run into any issues here.

Best regards,
Daniel