Working with variables and releases between environments

adam.tyson's Avatar


09 Jan, 2017 06:24 PM


We're currently evaluating Octopus to manage our deployments, and to replace TeamCity which is currently deploying via MSDeploy. We'll continue to use TC to do build the code and run tests.

At the moment we have separate config files for each environment (Test, PreProd, Prod etc) which are transformed in the TC build, with a separate config file for each environment. Not very efficient!

I like the idea of moving away from this and having Octopus take care of the different configuration values using variables, and get the config out of Git and multiple web.*.config files and into Octopus instead.

I'm a bit stuck on how to achieve this in Octopus, version 3.5.1. At first look it appears variables are managed per project, but I want them grouped by environment. If I'm promoting releases form Test to PreProd, I'd typically want the same code and iis set up but different config values.

Any thoughts on how I might do this? I'm happy to change the process if it can be achieved in a different way.

thanks in advance,


  1. Support Staff 1 Posted by Daniel Fischer on 10 Jan, 2017 04:31 AM

    Daniel Fischer's Avatar

    Hi Adam

    Thanks for getting in touch! In Octopus we provide the ability to scope variables to different environments for just these situations. The variable scoping is fairly straight forward and is very powerful. The idea is that you create multiple variables with the same name and different values in the project. You then scope each of those variables to different (or multiple) environments.
    When Octopus evaluates those variables, it will use the required variable based on the scoping. We have some fantastic documentation that covers this in detail which is well worth the read.

    So to give you an example:

    Say I have the environments DevTestProd I can create a hostname variable then assign it a value and give it a scope, I can do this as many times as I need.

    Variable Name hostname Value server1 Scope Dev
    Variable Name hostname Value server2 Scope Test
    Variable Name hostname Value server3 Scope Prod

    In the above example, I have 3 variables with the exact same name, so when I call them in my deploy step I would call #{hostname}. When it comes time to deploy, Octopus will check the environment it is deploying to and match it against the scope for that variable. If I were to deploy to Test, Octopus would notice that for the Test environment I require the server2 value for the hostname variable.

    If you require a set of variables that will be used over multiple projects, there is an option to create a Library variable set. These are sets of variables that can be configured outside the project and later imported into any project you need.
    If you would like to read the documentation on these the link is here:

    We also have some great documentation on how you can best implement your config files in Octopus.

    This idea can be used for any variable you need to call inside Octopus and gives you fine control over what information is deployed based on environment.

    Let me know if that helps.

    Best regards,

  2. 2 Posted by adam.tyson on 10 Jan, 2017 10:07 AM

    adam.tyson's Avatar

    Thank you Daniel for your thorough answer, I'll try setting it up as you suggest. I think this will work for us.


  3. Support Staff 3 Posted by Daniel Fischer on 10 Jan, 2017 11:59 PM

    Daniel Fischer's Avatar

    Hi Adam,

    No worries at all! We are always happy to help. Let me know if you run into any more issues or have any further questions.

    Best regards,

  4. Paul Stovell closed this discussion on 10 Apr, 2017 02:11 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac