Get Variable value from Tenant

Is there any way to get a variable value from tenant in Octopus server?

I already extracting variable value from projects, using code below, but this method is not working for tenants:

Import-Module “C:\Program Files\WindowsPowerShell\Modules\Octopus-Cmdlets\0.4.4\Octopus-Cmdlets.psd1”

connect-octoserver http://octohost.cloudapp.azure.com:8082 API-12345678901234567890
$raw = (Get-OctoVariable someproject somevariable | Where-Object { $_.Environment -eq “DEV” } )
$jsonfile = “c:\dataapi.json”
$raw.Value | ConvertFrom-Json | ConvertTo-Json | Out-File $jsonfile -Encoding UTF8
$data = Get-Content $jsonfile -Encoding UTF8 | ConvertFrom-Json
$data | ConvertTo-Json | Set-Content $jsonfile -Encoding UTF8

Perhaps there any other ways to retrieve variable value from tenant?

Hi Vegas,

Thanks for getting in touch! It’s possible to get a tenant’s variable value via the API, though tenant variables are accessed at /api/tenants/{id}/variables, which will get all variables for a single tenant, instead of /api/variables/. The PowerShell module it looks like you’re using (Octopus-Cmdlets) doesn’t seem to have added support for tenants, so I’m not sure if it’s possible using this module.

Unfortunately I couldn’t find any sample scripts to get a specific variable value from a tenant in our sample repo, though you can find more details on the tenantvariables resource in our API wiki.

Side note: In Octopus 3.17, we added the default Swagger UI for displaying the API docs in an easier way which may also help. This is accessed at [OctopusURL]/swaggerui, whereas the standard API is accessed at [OctopusURL]/api. :slight_smile:

I hope this helps! Don’t hesitate to reach out if you have any further questions going forward.

Best regards,

Kenny

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