I’m using Octopus 2018.8.8. How can I get a list of Tenant Names along with the Tenant Tags assigned?
I’ve been using PowerShell and the API and I’ve been able to get a list of Tenants, and separately a list of Tenant Tags belonging to a particular TagSet. But cannot figure out how to get them together.
My TagSet is called Integrations and looks something lie:
Integrations/Tag1
Integrations/Tag2
Integrations/Tag3
Tenant1 might have Integration/Tag2
Tenant2 might have Integration/Tag1 and Integration/Tag3
So what I’m after is a list of Tenants and which Integration tags they have.
Thanks for getting in touch! I may be oversimplifying your requirements here but I have created a simple API script using the Octopus.Client to get all Tenants and return their name, followed by their Tag Set / Tag.
For example, I have two Tenants (Tenant-A & Tenant-B) and two Tag Sets each with two tags (TagSet-A/Tag-1, etc). My script returns the following.
This script uses the Octopus.Client to get the Tenant’s on my instance and simply write out the name of each one and their connected Tag Set / Tags in a foreach loop.
Add-Type -Path 'C:\MyScripts\Octopus.Client.dll'
# Make sure you have a recent version! Here is how to check...
#[System.Diagnostics.FileVersionInfo]::GetVersionInfo('C:\MyScripts\Octopus.Client.dll').FileVersion
# Create endpoint and client.
# This uses the above Octopus.Client.dll to create an authenticated endpoint at your Octopus server and a client variable containing the API resources you will call on.
$endpoint = New-Object Octopus.Client.OctopusServerEndpoint("http://YourOctopusServer/", "API-KEY")
$client = New-Object Octopus.Client.OctopusClient($endpoint)
# Get all Tenants on server and add to $tenants variable
$tenants = $client.Repository.Tenants.FindAll()
# Foreach tenant in the variable, write the name then associated tag sets/tags.
foreach ($tenant in $tenants){
$tenant.name
$tenant.TenantTags
}
If this is not quite what you were after, let me know and I’ll help out however I can.
This is an older version of Octopus (2018.8.8 and Octopus.client.dll 4.47.0 because later versions require Spaces which we do not have access to with our version.) Any suggestions?
Thanks for getting back. I downloaded 2018.8.8 onto my VM and did some testing. It looks like the method I’m using to create the $client variable didn’t exist for this version of Octopus.client.
Specifically, creating a new object of Octopus.Client.OctopusClient
If you create a new Octopus.Client.OctopusRepository object then things should work. You will also need to edit the line where we FindAll tenants to reflect this change.
So changing our $client and $tenant variables, they should now look like this.