Accessing library variable sets from the script console

We’re trying to use Library variable values in scripts run ad-hoc in the script console, but I can’t work out if they are available or not, and if I have got the syntax correct to access them.

The Rationale is that within our security and ops constraints, ad-hoc data queries in SQL server are difficult to perform, and poorly audited. To do the same from Powershell in the script console is better audited and easier to perform, but we need the connection string, which is in a library.

So for example, the following script, run ad hoc:

Write-Host "Before"
Write-Host  $OctopusParameters["SomeService.ConnectionString"]
Write-Host "After"

results in an output, ending up with (truncated/sanitised):

14:55:57   Info     |     Script run completed successfully.
                    |   
                    |     Success: Tentacle script execution
14:55:57   Verbose  |       Running PowerShell script: C:\Users\octo331\AppData\Local\Tentacle\Temp\5c576587-0a14-49e5-86dd-170d35b22233.ps1
14:55:57   Info     |       Before
                    |       After
14:55:57   Info     |       ==============================================
                    |       PowerShell exit code: 0
                    |       ==============================================
                    |     

The implication is that the variables are not available, or I have the syntax wrong. The following script implies the variables are simply missing?

Write-Host "Before"
$OctopusParameters | ConvertTo-Json | Write-Host
Write-Host "After"

which results in output like (slightly sanitised):

{
    "Octopus.Tentacle.Agent.InstanceName":  "Tentacle",
    "Octopus.Tentacle.Agent.ApplicationDirectoryPath":  "C:\\Octopus\\Applications",
    "Octopus.Tentacle.Agent.ProgramDirectoryPath":  "C:\\Octopus\\Applications\\.SQ-XXXXXXX-CF2D2BC5\\Octopus.Tentacle\\2.5.12.666"
}

Extra info:
I’m running the script against an environment and machine role which normally has access to the variable in question.
Indeed we’ve used SomeService.ConnectionString in Deploy.Ps1 scripts as part of projects on this same instance, just never before from the script console
Octopus version 2.5.12.666
I also understand that my very examples above show that this functionality may be considered a security risk (ie, you can pipe the library secrets into a log). But the point is, only admins who can access those secrets anyway are allowed to run these scripts, and they’re audited nicely.
I’ve tried all of the following syntax variations, none have worked. “SomeService.ConnectionString” is the variable, “ConnectionStrings” is the variable set in the library.

$OctopusParameters["ConnectionStrings.SomeService.ConnectionString"] | Write-Host
$OctopusParameters["SomeService.ConnectionString"] | Write-Host
$ConnectionStringsSomeServiceConnectionString | Write-Host
$SomeServiceConnectionString | Write-Host
#{ConnectionStrings.SomeService.ConnectionString} | Write-Host
#{ConnectionStrings.SomeService.ConnectionString} | Write-Host

(The last two obviously don’t work, as # is the comment character in powershell)

Hi Andrew,

Thanks for reaching out. Its not currently possible to use Octopus variables from the script console. I’ve created a uservoice request so people can vote if they want to see this implemented on upcoming versions. Please feel free to drop by and add some votes

Thanks

Dalmiro

Any update on this? It would make it much easier to test your scripts.

Hi,

Thanks for reaching out. I’m afraid still not. The suggestion hasn’t been popular enough to get into our radar. If you could add a comment on the suggestion that would explain a real life scenario where this could be needed, it would help making a case.

Thanks,

Dalmiro