Powershell script help for duplicating environment scope

Hello,

We tend to create new environments all the time in our current setup. They are often very similar to, or at least share many similar properties with, previously created and configured environments.

In order to save time, I would like to be able to duplicate the scope of all applicable variables of a particular environment into another. The variables with no scope will not be affected, but those that are scoped to, say, Env1, now need to have Env2 (the newly created environment) as well.

Is there a quick way to do this, preferably using Powershell? Any help would be greatly appreciated.

Thank you,
Arvindh Mani

Hi Arvindh,

Thanks for getting in touch! This is currently something we do not have a good built-in method for handling in Octopus.

Outside of scripting this yourself there is really only one method we can think of. It would involve some refactoring in Octopus which may be more trouble than it’s worth but I’ll suggest it anyway.

This method involves modifying your variables to use a set of convention and then using those naming convention with your Environments. For example, if you had a database name which you need to be applied to only Prod.Env1, you could simply have the variable as a part of your connection string like this acme-#{Octopus.Environment.Name}-sql. This would automatically adapt your variables to the environment you are deploying to.

This is currently the best solution we can think of inside Octopus to help you achieve this. We know of a couple of customers who have had some success with this method but it does require a lot of work to refactor your variables.

As I noted, the alternative would be to write some custom script, which would be more of a difficult solution.

This is a scenario we have considered and talked about internally for some time. We don’t currently have anything in the works for it but we can say it is on our list of desired features for the future.

We are constantly evolving Octopus and its capabilities, in the future this is something we would like to have a great solution for.

If you have any questions or thoughts on this, please don’t hesitate to let me know.

Best regards,
Daniel

Thank you for your response, Daniel.

We already have the variables customized by including the environment name in them, so that is already something we do :slight_smile: I was actually thinking of writing a script to duplicate scopes, but among the available Octopus APIs, I am unable to find the best way forward. Would you perhaps be able to guide me in the right direction here?

Hi @arvindhmani,

Thanks for the update here. I don’t have any examples available for achieving exactly this, however, the following GitHub repo has a handful of API scripts you can use as a reference for working with Variables in Octopus.

This may help give you an idea on how to get started with this.

If you have any further questions on this, please don’t hesitate to let me know.

Best regards,
Daniel

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.