Octopus 3.12.0. I have just started trying to use channels but my library variables are not being defined.
According to https://octopus.com/docs/key-concepts/projects/channels#Channels-Variables
I should be able to scope variables to a channel, but I don’t get that option.
Under ‘Scope specificity’, here: https://octopus.com/docs/deploying-applications/variables/scoping-variables
it says ‘The target channel (if channels are enabled)’
How do I enable channel scoping for variables?
Mark
Hi Mark,
Thanks for getting in touch! Since channels are defined per project, only project variables can be scoped to channels. So library variables cannot be scoped to channels.
If you already have a number of variables created in a variable set, we have an example PowerShell script that may help. This will duplicate variables from a library variable set to a project. After running this, you can then scope your new project variables to your channels.
$baseUri = "http://octopus.url" # <-- Update this to the base URL to your Octopus server(i.e. not including 'app' or 'api'
$apiKey = "API-xxxxxxxxxxxxxxxxxxxxxxxxxx" # <-- Update this to your API key
$headers = @{"X-Octopus-ApiKey" = $apiKey}
$libraryVariableSetId = "LibraryVariableSets-1" # <-- Update this to the Id of your variable set
$projectName = "ProejctName" # <-- Update this to the name of your project
function Get-OctopusResource([string]$uri) {
Write-Host "[GET]: $uri"
return Invoke-RestMethod -Method Get -Uri "$baseUri/$uri" -Headers $headers
}
function Put-OctopusResource([string]$uri, [object]$resource) {
Write-Host "[PUT]: $uri"
#Write-Output $resource | ConvertTo-Json -Depth 10
Invoke-RestMethod -Method Put -Uri "$baseUri/$uri" -Body $($resource | ConvertTo-Json -Depth 10) -Headers $headers
}
$libVarSet = Get-OctopusResource "api/libraryvariablesets/$libraryVariableSetId"
#Write-Output $libVarSet | ConvertTo-Json -Depth 10
$varSet = Get-OctopusResource "api/variables/$($libVarSet.VariableSetId)"
This file has been truncated. show original
I hope this helps! Let me know if you have any further questions.
Best regards,
Kenny
Thanks Kenny, I can work with that.
Mark