Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the list of user variables from Octopus

we have Octopus-2.0. We stored the service credentials (they are per machine) in octopus user variable. I need to create these login in SQL server as well.

For Example service login name "machine1_service1" stored as variable name. and password of that login is stored under column Variable Value in octopus.

so far i know that to any variable value from octopus we need to provide exact variable name. but in this case I actually need to get list of all these variables.

Is there a way to accomplish this?

like image 380
Anup Shah Avatar asked Feb 10 '23 08:02

Anup Shah


1 Answers

Yes.

Octopus variables are accessible from a dictionary object that can be enumerated. If you follow a naming convention you could query the dictionary using powershell with something like the following. This would be called from within a custom step or somewhere where you can write your own powershell e.g. a PostDeploy.ps1 script in the .nuget file

Let's say the variables are defined like this

enter image description here

You can use this powershell to get to them and enumerate round them

# Get service accounts
$serviceAccounts = $OctopusParameters.keys | ? {$_ -like "service-*"}
write-host "Accounts found:" $serviceAccounts.count

foreach($account in $serviceAccounts)
{
    write-host "Account: $account"

    $password = $OctopusParameters[$account]
    write-host "Password: $password"
}

Hope this helps.

like image 163
Evolve Software Ltd Avatar answered Mar 03 '23 22:03

Evolve Software Ltd