Variable Sets with Project Specific Values

I have a lot of variables that are set per project, but the variable names, scopes, descriptions, etc are the same across all of the projects.

Is there a way to define a global Variable Set and then just set the values in the project?

For example, I would have the following variable in the set:

Variable Name:         ApplicationName
Variable Description:  Name of the application as defined in the App Database
Variable Scopes: 
     Environments:     Dev, Test, Stage, Prod
     Channels:         Release, HotFix

I have many more like this (ProductName, MaxPods, MinPods etc). I would like to define these in one Variable Set, and then just set the values in each of the projects (without having to define the variable again in the project).

Is there a way to do this?

Hi @OctopusSchaff,

Thanks for reaching out with your question.

It looks like you might be looking for Variable Templates within Library -> Variable Sets.

Once you have everything you want as a Template you’ll be able to link the Library Variable set to the Project like normal and it will pull in your Common variables:

Please let me know if this will work for you.

Regards,
Garrett

I can’t see a way for this to allow me to set the values per project.

I can set them in the Common Variable Templates section, but I don’t see a way to change the value per project.

Is there a way to define a variable once, and then set it in each project?

Hi @OctopusSchaff,

Sorry for the misunderstanding I believe I get what you’re saying now.

There doesn’t seem to be a way to do this through the UI but you could use something like this Powershell API script to add variable sets in the way you’re describing:

You will fill out your values at the bottom around line #145. As with any script, please understand and test before running in a production environment.

Please let me know if this helps!

Regards,
Garrett

While I don’t mind using scripts, the people who actually have to set the values in each project will not feel comfortable doing that.

While tedious and a bit error prone, I will just continue creating the variables manually in each project so they can use the normal editors of Octopus when they set the values.

Hi @OctopusSchaff,

Thanks for getting back to me with your use case. You should be able to run this script and basically “import” a set of Project Variables that will be editable by anyone that has access to the Project. This way you can easily define a list of common variables into the Project, for example:

Add-Variable -VariableSet $octopusProjectVariables -VariableName "TestNew3" -VariableValue "Nothing scoped"
Add-Variable -VariableSet $octopusProjectVariables -VariableName "TestNew4" -VariableValue "Nothing scoped"
Add-Variable -VariableSet $octopusProjectVariables -VariableName "TestNew5" -VariableValue "Nothing scoped"
Add-Variable -VariableSet $octopusProjectVariables -VariableName "TestNewEnv2" -VariableValue "Env Scoped" -VariableEnvScope "Development"
Add-Variable -VariableSet $octopusProjectVariables -VariableName "TestNewRole" -VariableValue "Role Scoped" -VariableRoleScope "Web"
Add-Variable -VariableSet $octopusProjectVariables -VariableName "ObjectTesting2" -VariableValue "Both Env and Role Scoped" -VariableEnvScope "Development" -VariableRoleScope "Web"

The above would turn into:

You can also leave a blank in the value field like so: VariableValue = "" and it would show up as Enter value like this on the Project side:

I understand it’s a bit of overhead for you but, hopefully, this can get you to where you need to be.

Regards,
Garrett

3 Likes