Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Adding a variable to Octopus Deploy project issues

$
0
0

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)
        
    }



Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>