I want to add a single variable to the project. Not part of a variable set but just one single variable. I am getting an error saying:
This is my code and does not give me an error but it does not add the variable to the project.
Any ideas why??
#Add a new variable to the project
Add-Type -Path 'C:\temp\Octopus.Client.dll'
$endpoint = New-Object Octopus.Client.OctopusServerEndpoint $OctopusUrl,$APIKey
$client = New-Object Octopus.Client.OctopusClient $endpoint
$space = $client.ForSystem().Spaces.FindByName($SpaceName)
$spaceRepository = $client.ForSpace($space)
#Add a new variable to the project
$project = $spaceRepository.Projects.FindByName($ProjectName)
$variableset = $spaceRepository.VariableSets.Get($Project.links.variables)
$newVariable = New-Object Octopus.Client.Model.VariableResource
$newVariable.Name = "PackageName"
$newVariable.Value = "Package.Common.DataConcerns"
$variableset.Variables.Add($newVariable)