We try to use multi-tenant feature to support deployments of our git topic branches. In order to do this tenants have to be dynamically created and deleted through the rest API. So far this works out very good. Now we need to assign values to the tenant’s template variables and this is where we have a problem. Here is what we did.
- Right after the tenant has been created we used
GET "/api/tenants/{tenant.Id}/variables"
to get the list of variables that are expected to be assigned the values. Here is the sample response:
{
"TenantId": "Tenants-104",
"TenantName": "topic #ent-999",
"LibraryVariables":{
"LibraryVariableSets-82":{
"LibraryVariableSetId": "LibraryVariableSets-82",
"LibraryVariableSetName": "Git Branching Support",
"Templates":[{
"Id": "6a89d0f9-0ce4-4c6e-b693-314529df25ac",
"Name": "Tenant.IISWebAppPath",
"Label": "IIS Web Application Path",
"HelpText": "Alias to be assigned to this tenant's (git branch) web application within the module's web site",
"DefaultValue": null,
"DisplaySettings":{
"Octopus.ControlType": "SingleLineText"
}
}],
"Variables":{},
"Links":{
"LibraryVariableSet": "/octopus/api/libraryvariablesets/LibraryVariableSets-82"
}
}
},
"Links":{
"Self": "/octopus/api/tenants/Tenants-104/variables",
"Tenant": "/octopus/api/tenants/Tenants-104"
}
}
- The property
Variables
is an empty object and this is where we need to put the value for the template variable. So, we added it and usedPOST "/api/tenants/{tenant.Id}/variables"
with the following payload:
{
"TenantId": "Tenants-104",
"TenantName": "topic #ent-999",
"LibraryVariables":{
"LibraryVariableSets-82":{
"LibraryVariableSetId": "LibraryVariableSets-82",
"LibraryVariableSetName": "Git Branching Support",
"Templates":[{
"Id": "6a89d0f9-0ce4-4c6e-b693-314529df25ac",
"Name": "Tenant.IISWebAppPath",
"Label": "IIS Web Application Path",
"HelpText": "Alias to be assigned to this tenant's (git branch) web application within the module's web site",
"DefaultValue": null,
"DisplaySettings":{
"Octopus.ControlType": "SingleLineText"
}
}],
"Variables":{
"6a89d0f9-0ce4-4c6e-b693-314529df25ac": "ent-999"
},
"Links":{
"LibraryVariableSet": "/octopus/api/libraryvariablesets/LibraryVariableSets-82"
}
}
},
"Links":{
"Self": "/octopus/api/tenants/Tenants-104/variables",
"Tenant": "/octopus/api/tenants/Tenants-104"
}
}
We got (500) Internal Server Error
from the server. After that we examined what Octopus UI does and here is the payload that’s been sent:
{
"TenantId":"Tenants-104",
"TenantName":"topic #ent-999",
"LibraryVariables":{
"LibraryVariableSets-82":{
"LibraryVariableSetId":"LibraryVariableSets-82",
"LibraryVariableSetName":"Git Branching Support",
"Templates":[{
"Id":"6a89d0f9-0ce4-4c6e-b693-314529df25ac",
"Name":"Tenant.IISWebAppPath",
"Label":"IIS Web Application Path",
"HelpText":"Alias to be assigned to this tenant's (git branch) web application within the module's web site",
"DefaultValue":null,
"DisplaySettings":{
"Octopus.ControlType":"SingleLineText"
},
"$$hashKey":"object:458"
}],
"Variables":{
"6a89d0f9-0ce4-4c6e-b693-314529df25ac":"ent-999"
},
"Links":{
"LibraryVariableSet":"/octopus/api/libraryvariablesets/LibraryVariableSets-82"
}
}
},
"LibraryVariableSetVariableTemplates":{
"LibraryVariableSets-82":{
"LibraryVariableSetId":"LibraryVariableSets-82",
"LibraryVariableSetName":"Git Branching Support",
"Templates":[{
"Id":"6a89d0f9-0ce4-4c6e-b693-314529df25ac",
"Name":"Tenant.IISWebAppPath",
"Label":"IIS Web Application Path",
"HelpText":"Alias to be assigned to this tenant's (git branch) web application within the module's web site",
"DefaultValue":null,
"DisplaySettings":{
"Octopus.ControlType":"SingleLineText"
},
"$$hashKey":"object:458"
}],
"Variables":{
"6a89d0f9-0ce4-4c6e-b693-314529df25ac":"ent-999"
}
}
},
"Links":{
"Self":"/octopus/api/tenants/Tenants-104/variables",
"Tenant":"/octopus/api/tenants/Tenants-104"
}
}
What immediately stood out was the extra property LibraryVariableSetVariableTemplates
which was the exact copy of LibraryVariables
. The other difference was the extra property $$hashKey
in the property Templates
. The documentation is of no help here. Could you please guide me in how to assign a value to a tenant’s template variable?
Thanks,
Rosti Grigoriev