Find all tenants with variables i none go?

We want to use Octopus.Client to internal integrations.

We need to find all tenants with its variables. Asking for variables one by one takes long time.
Is there posibility to take tenants with variables on one go?

$endpoint = New-Object Octopus.Client.OctopusServerEndpoint($server, $apiKey)
$client = New-Object Octopus.Client.OctopusClient($endpoint)
$tenants = $client.Repository.Tenants.FindAll()

Method FindAll has parameters but we can’t find any documentation about it.

Hi Dariusz,

Thanks for getting in touch! As the Tenant variables are not available at the Tenants endpoint in our API, you won’t be able to get them without calling either the VariableSet endpoint, or in the Octopus.Client, you can use $client.Repository.Tenants.GetVariables($tenant). Furthermore, working with variables in the client can be a little difficult as they’re stored as JSON objects which need to be deserialized.

I just tested this on my end and the below command works, though you will need to parse the JSON output to work with it. This isn’t very eloquent, but hopefully it helps you get the ball rolling and gives you a better idea of how to get the variables.

$tenants = $client.repository.Tenants.FindAll()
foreach ($tenant in $tenants){
    Write-Host "Tenant: $($tenant.Name)"
    $variables = $client.repository.Tenants.GetVariables($tenant).ProjectVariables.Values.Variables
    foreach ($variable in $variables) {
        Write-Host "Variables: $($variable.Values | ConvertTo-Json)" 
    }
}

If you have any questions or thoughts on this, please don’t hesitate to let me know.

Best regards,
Daniel

Thanks for help. This is how we do it. I ask for it because it works kinda slow but for our need thats not a big problem. We will execute that only once per hour.

Thanks.

2 Likes

Hey @dariusz.lenartowicz,

Just jumping in for Daniel as he wont be online for a while yet as part of our Australian based team, greats news you have already set this up as Daniel did, that confirms that is the way to go when you are trying to find all the tenants with its variables.

I am sorry this is quite a slow process for you, as Daniel mentioned, this is the only way to do this since the Tenant variables are not available at the Tenants endpoint in our API so Octopus needs to grab them from various places and as Daniel mentioned, they are stored as JSON objects which need to be deserialized so that would also take a bit of time to do.

If you have many tenants with a lot of variables that is why it will probably be taking a long time,
you mentioned this is not a big problem for you at the moment which is good news and we have not had any reports of other customers being affected by this.

I do not think our engineers could make this process quicker but if you do find its taking too long and it is negatively affecting deployments please reach out and we can take another look at this.

Kind Regards,
Clare

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.