Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Creating an (incomplete) OctoPosh variableset object
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
You can’t perform that action at this time.