Is there is any way to Export Octopus Environment and Variable sets from on Server to another?

Hi Team,

we are trying to Export Octopus Environment and Variable sets from Octopus 3.16.7 version to 2018.10.0 version , is there is any way to achieved this . Please help

Hello,
Thanks for getting in touch! While you can’t export variable sets from Octopus 3.16.7 Portal UI you should be able to achieve this using the API directly.

We have a handy OctopusDeploy-Api repository on github which might already contain a script that will take care of your desired task. I have tested one method to export variables out of Octopus Version 3.16.7.

I start with a library variable set that looks like this:

Then, after generating an API Key in my User Profile, I was able to make use of the script we’ve put together called GetVariablesFromVariableSet.ps1

This was the script I ran to export the variables:

##Config
$OctopusAPIkey = "API-xxxxxxLNT5YDDES53TTJxxxxxxxx"#Octopus API Key
$OctopusURL = "https://xxxxxxxxx"#Octopus URL
$variableSetName = "test" #Name of the variable set
$header = @{ "X-Octopus-ApiKey" = $octopusAPIKey }

##Process
$VariableSet = (Invoke-WebRequest "$OctopusURL/api/libraryvariablesets?contentType=Variables" -Headers $header).content | ConvertFrom-Json | select -ExpandProperty Items | ?{$_.name -eq $variableSetName}
$variables = (Invoke-WebRequest "$OctopusURL/$($VariableSet.Links.Variables)" -Headers $header).content | ConvertFrom-Json | select -ExpandProperty Variables
$variables #<--- Collection of variables of the variable set

The end result in PowerShell looks like this:

Id          : 63ac7f6b-2d04-bf40-fa20-3ca0b739d689
Name        : test1
Value       : test1
Scope       : 
IsEditable  : True
Prompt      : 
Type        : String
IsSensitive : False

Id          : ca381c40-313d-c854-ae35-85db27a76ab6
Name        : test2
Value       : test2
Scope       : 
IsEditable  : True
Prompt      : 
Type        : String
IsSensitive : False

Id          : 391ecc1e-3353-f40e-3733-821e2a75bb60
Name        : somevariablename
Value       : this is the value of that variable.
Scope       : 
IsEditable  : True
Prompt      : 
Type        : String
IsSensitive : False

Hopefully this information will get you started on scripting out a way to move these variables to your new project. I also looked into whether our Octopus Migrator would help you here but it would not work here because both the source and destination Octopus Servers need to be the exact same version as each other.

Kind regards,
Lawrence.

1 Like