I am using PowerShell to create a Tenant for a multi-tenanted deployment. I can create the tenant successfully and apply tag sets to it. For each tenant there are two variables to fill in, DBName and ServerName, but I cannot see how to assign values to them.
I have tried various things based on entries I’ve found on this support website and the wider internet, but to no avail.
I have tried the following based on a previous support post:
Add-Type -Path ‘C:\Program Files\Octopus Deploy\Octopus\Octopus.Client.dll’
$apikey = ‘API-’ # Get this from your profile
$octopusURI = ‘http://OctopusDeploy’ # Your Octopus Server address
$endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURI, $apiKey
$repository = New-Object Octopus.Client.OctopusRepository $endpoint
$project = $repository.Projects.FindByName(“Spotlight Database MT”)
$environment = $repository.Environments.FindByName(“Framework Dev”)
$tenantEditor = $repository.Tenants.CreateOrModify(“CM Test”)
$tenantEditor.WithTag($tagSet.Tags[1]) #Tags[1] is FDScheduled
$tenantEditor.ConnectToProjectAndEnvironments($project, $environment)
$Vars = $TenantEditor.Variables.Instance.LibraryVariables.Values[0]
$VarSet = $Vars.‘LibraryVariableSets-23’
$VarTemplate = $VarSet.Templates | Where-Object -Property Name -eq “DBName”
$VarSet.Variables[$varTemplate.Id] = “database_name”
$tenantEditor.Save()
The tenant is created successfully, but I cannot set the variables whatever I do.
I have also tried going through the projects collection (replacing the variable set block above), but that doesn’t work either.
$Vars = $TenantEditor.Variables.Instance.ProjectVariables
$VarSet = $Vars.‘Projects-361’
$VarTemplate = $VarSet.Templates | Where-Object -Property Name -eq “DBName”
$VarSet.Variables[$varTemplate.Id] = “database_name”
Any help would be greatly appreciated, the object model is unfathomable to me.
Thanks,
Chris.