Hi,
I am adding a variable to a Octopus Project and I cant get it to work. I am getting an error -
You cannot call a method on a null-valued expression.
$project.Variables.AddOrUpdateVariableValue($newVariable)
My $newVaraible returns what it should so I cant see why it is giving me a null error.
Code:
$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
$newVariable = New-Object Octopus.Client.Model.VariableResource
$newVariable.Name = "PackageName"
$newVariable.Value = "Package.Common.DataConcerns"
# Find the project you want and add the variable to
foreach ($name in $ProjectName) {
$project = $spaceRepository.Projects.FindByName($name)
$project.Variables.AddOrUpdateVariableValue($newVariable)
$spaceRepository.Projects.Modify($project)
}