Skip to content

Instantly share code, notes, and snippets.

@Dalmirog-zz
Last active August 29, 2015 14:16
Show Gist options
  • Save Dalmirog-zz/aad81d3a64b279c0c4af to your computer and use it in GitHub Desktop.
Save Dalmirog-zz/aad81d3a64b279c0c4af to your computer and use it in GitHub Desktop.
UpdateOctopusVariables
#Easiest way to get these dlls is to find them
#on the tentacle/Octopus install dir like i'm doing here
Add-Type -Path "C:\Program Files\Octopus Deploy\Tentacle\Newtonsoft.Json.dll"
Add-Type -Path "C:\Program Files\Octopus Deploy\Tentacle\Octopus.Client.dll"
Add-Type -Path "C:\Program Files\Octopus Deploy\Tentacle\Octopus.Platform.dll"
$OctopusURL = "" #eg "http://BestDeploymentTool.mycompany.com"
$APIKey = "" #eg "API-YHMOPNVMRLFXJBV4EQRDIDNDJ"
$endpoint = new-object Octopus.Client.OctopusServerEndpoint ($OctopusURL, $APIKey)
$c = new-object Octopus.Client.OctopusRepository $endpoint
$Pattern = "" #accepts wildcards
$newvalue = "" # New value to set to the variable. It will change the entire variable value to this
$projects = $c.Projects.FindAll()
foreach ($project in $projects){
$variableset = $c.VariableSets.Get($project.links.variables)
If ($variableset.Variables.value -like $Pattern){
write-output "Pattern found on a variable on project: $($project.name). Updating variable set..."
$variableset.Variables | ?{$_.value -like $Pattern} | %{$_.value = $newvalue}
$c.VariableSets.Modify($variableset)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment