Can't access the Library variableset from C# code

we are trying to access a variable which is present under a library variable set from c# code. Can you please provide a sample code snippet which can accomplish this task.

We did go through the below link however the link provides the tutorial for accessing a variable under a project and not a variable under library variable set:

Any help will be much appreciated, thanks!

Hi,

Thanks for reaching out. You should be able to get a Library Variable set by using octopus.LibraryVariableSets.FindByName("MyVariableSetName"), but apparently FindByName Isn’t working as it should (I’ll let the team know). For now you can use octopus.LibraryVariableSets.FindAll to get a list of all the Library Variable Sets and then filter the one you wanna use.

Hope that helps,
Dalmiro

Thanks for the reply Dalmiro!

I’m using octopus.LibraryVariableSets.FindAll and was able to retrieve the VariableSet name however I’m not able to access the variables under it.

The whole purpose is that we are looking to edit a variable (under LibraryVariableSet) from C# code.

I’m using below, although I’m getting the desired variableSet in myVariableSet but can’t find any associate functions to retieve the variables inside it:

var allVariableSets = octopus.LibraryVariableSets.FindAll();
var myVariableSet = allVariableSets[0];

Thanks!

Hi,

myVariableSet will have an ID property. You need to pass that ID string to Octopus.VariableSets.Get("TheID") and you’ll get your variables.

Thanks,
Dalmiro