Update one scope value for value with multiple scopes

We’re updating a certificate hash from CertifyTheWeb via a powershell script that uses Octopus.Client.dll. However, there are separate thumbprints depending on the environment. How do i update just one scope value for a variable. I can do it with just one:

# https://www.nuget.org/packages/Octopus.Client/
Add-Type -Path "$currentDir\Octopus.Client.dll"

$endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octoServer,$octoApiKey 
$repository = New-Object Octopus.Client.OctopusRepository $endpoint

####    Modify the "SD.SslThumbprint" value in the "Standard SD Variable Set"   ####
$libraryVariableSet = $repository.LibraryVariableSets.FindByName("Standard SD Variable Set")

$variables = $repository.VariableSets.Get($libraryVariableSet.VariableSetId);

$sslThumbprintVariable = $variables.Variables | ? Name -eq "SD.SslThumbprint"

$sslThumbprintVariable.Value = $thumbPrint;

#$variables.AddOrUpdateVariableValue("SD.SslThumbprint", "Test")

$response = $repository.VariableSets.Modify($variables);
"Octopus Updated"

But how do I modify just one particualar variable value with a certain environment?

Hi Brandon,

Thanks for getting in touch!

A colleague recently added a sample script using the REST API rather than the Octopus.Client that has the ability to modify specific scoped values without affecting the others. Having a look through his Modify-Variable function should hopefully help point you in the right direction.


Thank you for this. I made some changes so that I could use an empty “spaces” name (we need to upgrade) and also changed Modify-Variable to support environments as an array when more than one environment is assigned. IE:

        if ($variable.Name -eq $VariableName -and $environments -contains $environmentId) {
            $variable.Value = $VariableValue
1 Like

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.