Created
October 7, 2017 20:57
-
-
Save JamesDawson/54a09171911403e4bb68c8bd292031e7 to your computer and use it in GitHub Desktop.
Creating an (incomplete) OctoPosh variableset object
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
| function New-MockVariableSet([hashtable]$props) | |
| { | |
| $varset = new-object 'OctoPosh.Model.OutputOctopusVariableSet' | |
| $varset.ID = $props.Id | |
| $varset.LibraryVariableSetName = $props.Name | |
| $varset.Variables = new-object 'System.Collections.Generic.List[OctoPosh.Model.FriendlyVariable]' | |
| $varset.Resource = new-object 'Octopus.Client.Model.VariableSetResource' | |
| $varset.Resource.Id = $props.Id | |
| foreach ($v in $props.Variables) | |
| { | |
| $var = new-object 'OctoPosh.Model.FriendlyVariable' | |
| $var.Name = $v.Name | |
| $var.Value = $v.Value | |
| $var.Scope = new-object 'OctoPosh.Model.FriendlyScopeCollection' | |
| $var.Scope.Environments = $v.Scope.Environments | |
| $varset.Variables.Add($v) | |
| $resvar = new-object 'Octopus.Client.Model.VariableResource' | |
| $resvar.Id = [Guid]::NewGuid().ToString() | |
| $resvar.Name = $v | |
| $envscope = new-object 'Octopus.Client.Model.ScopeSpecification' | |
| $envscope_value = new-object 'System.Collections.Generic.HashSet[string]' | |
| $v.Scope.Environments | ? { $_ } | % { $envscope_value.Add($_) } | Out-Null | |
| $resvar.Scope.Add([Octopus.Client.Model.ScopeField]::Environment, $envscope_value) | |
| $varset.Resource.Variables.Add($resvar) | |
| } | |
| return $varset | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment