Last active
May 26, 2016 09:32
-
-
Save Dalmirog-zz/89626e8fd7833ed8de09 to your computer and use it in GitHub Desktop.
Create and Octopus Project Variable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Config | |
$OctopusURL = "" #Octopus URL | |
$APIKey = "" #Octopus APIKey | |
$projectname = "" #Name of the project | |
$Name = "" #Name of the variable | |
$Value = "" #Value of the variable | |
#Loading Octopus libraries and craeting a connection | |
#Easiest way to get these dlls is to find them | |
#on the tentacle/Octopus install dir like i'm doing here | |
#or to download them from here https://www.nuget.org/packages/Octopus.Client/ | |
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" | |
$endpoint = new-object Octopus.Client.OctopusServerEndpoint ($OctopusURL, $APIKey) | |
$c = new-object Octopus.Client.OctopusRepository $endpoint | |
#Getting the project by name | |
$project = $c.Projects.FindByName($projectname) | |
#Getting the project's variable set | |
$variableSet = $c.VariableSets.Get($project.links.variables) | |
#Creating a variable object and adding mandatory values to it | |
$newVariable = New-Object Octopus.Client.Model.VariableResource | |
$newVariable.name = $name | |
$newVariable.Value = $value | |
$newVariable.IsSensitive = $false #Set to $true if you want to treat this variable as sensitive | |
#Scope examples | |
#$newVariable.Scope.Add([Octopus.platform.Model.Scopefield]::Environment, (New-Object Octopus.Platform.Model.ScopeValue("Environments-1","Environments-2"))) | |
#$newVariable.Scope.Add([Octopus.platform.Model.Scopefield]::Role, (New-Object Octopus.Platform.Model.ScopeValue("WebServer","Database"))) | |
#$newVariable.Scope.Add([Octopus.platform.Model.Scopefield]::Machine, (New-Object Octopus.Platform.Model.ScopeValue("Machines-1"))) | |
#$newVariable.Scope.Add([Octopus.platform.Model.Scopefield]::Action, (New-Object Octopus.Platform.Model.ScopeValue("7455dcd0-c3b3-4ea0-a4c5-58acb6d0a855"))) | |
#adding new variable to variable set | |
$variableSet.Variables.Add($newVariable) | |
#Saving variable set changes to DB | |
$variableSet = $c.VariableSets.Modify($variableSet) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment