Our company has been a long term user of Octopus for our deployments and heavily use the API to interact with the server via Octopus.Client. We have recently gotten a brand new Octopus server on a newer version. Our previous version was version 3.3.27 and our new version is 2020.5.249.
We are testing out the API methods we previously used on the new server and found that we are no longer able to add variables to a library set. When doing so we receive the following error.
Exception calling "Modify" with "1" argument(s): "Octopus Server returned an error: Object reference not set to an instance of an object."
Add-Type -Path '.\lib\net452\Octopus.Client.dll'; $apikey = 'API-KEY' # Get this from your profile $octopusURI = 'OCTO-SERVER' # Your server address $libraryVariableSetId = "LibraryVariableSets-21" # Get this from /api/libraryvariablesets $variableName = "FirstName" # Name of the new variable $variableValue = "Michael" # Value of the new variable $endpoint = new-object Octopus.Client.OctopusServerEndpoint $octopusURI,$apikey $repository = new-object Octopus.Client.OctopusRepository $endpoint $libraryVariableSet = $repository.LibraryVariableSets.Get($libraryVariableSetId); $variables = $repository.VariableSets.Get($libraryVariableSet.VariableSetId); $myNewVariable = new-object Octopus.Client.Model.VariableResource $myNewVariable.Name = $variableName $myNewVariable.Value = $variableValue $variables.Variables.Add($myNewVariable) $repository.VariableSets.Modify($variables)
I even created a demo Octopus server on the absolutely newest version (Version 2021.1 Build 7236) and still got the same error.
Is this a known bug and if not what am I doing wrong here? Did the API syntax to add variables change?