I am using the Octopus Client (version 4.15.5) to copy variables in a variable set between a dev and production Octopus (version 3.11.4) server. I ran into an issue when I copied over a variable that was scoped to an environment whose ID is different between the environments. The variable copied over fine (no warning/error messages), but the variable didn’t work as expected. Upon further inspection I found that the Variable Set screen showed the variable as unscoped and the Variable Scope screen showed a blank space where the environment’s name usually shows, but these seem to be placeholders for a environment that has a different ID on my production server.
Here’s a snippet of the C# code that I’m using.
var devLibraryVariableSet = devRepository.LibraryVariableSets.FindAll().First(t => t.Name == "My.VariableSet");
var devVariableSetLink = devLibraryVariableSet.Links.First(t => t.Key == "Variables");
var devVariableSetResource = devRepository.VariableSets.Get(devVariableSetLink.Value);
var devVariables = devVariableSetResource.Variables.Where(v => v.Name.Contains("My.Variable"));
var prodLibraryVariableSet = prodRepository.LibraryVariableSets.FindAll().First(t => t.Name == "My.VariableSet");
var prodVariableSetLink = prodLibraryVariableSet.Links.First(t => t.Key == "Variables");
var prodVariableSetResource = prodRepository.VariableSets.Get(prodVariableSetLink.Value);
var prodVariables = prodVariableSetResource.Variables;
foreach (var variable in devVariables)
{
//if it doesn't already exist
if(!prodVariables.Any(v => v.Id == variable.Id))
{
prodVariables.Add(variable);
}
}
prodRepository.VariableSets.Modify(prodVariableSetResource);
I have a workaround, which is to adjust my copy logic to lookup the environment’s ID based on name; however, I expect that this is a bug that you would like to know about and possibly fix.