Passing a hash table between steps

Im failing trying to share a hash table between steps in an octopus project. In short i want to generate a bunch of keys once and then have all the machines where the code runs use those keys but i have made it much simpler to show my problem.

-Step A script
$foo=@{“a” = “aval”;“b” = “bval”;“c” = “cval”}
$foo
Set-OctopusVariable -name “ht” -value $foo

-Step B Script
write-host “hashtable back out”
$bar = $OctopusParameters[“Octopus.Action[A].Output.ht”]
write-host “plain”
$bar
write-host “enum”
$bar.GetEnumerator()

-output
| == Success: Step 4: B ==
20:51:39 Verbose | B completed
|
| Success: SharedTentacle
20:51:35 Verbose | Octopus Server version: 3.3.1+Branch.master.Sha.e396cf22d54f41a30788b619666a8517ea60d2b9
20:51:35 Info | Executing script on 'SharedTentacle’
20:51:36 Verbose | Octopus Deploy: Calamari version 3.3.1+Branch.master.Sha.25c4524418a3a9922cde6da7ebf074dba37ea326
20:51:38 Verbose | Name Value
20:51:38 Verbose | ---- -----
20:51:38 Verbose | PSVersion 5.1.14394.1000
20:51:38 Verbose | PSEdition Desktop
20:51:38 Verbose | PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
20:51:38 Verbose | BuildVersion 10.0.14394.1000
20:51:38 Verbose | CLRVersion 4.0.30319.42000
20:51:38 Verbose | WSManStackVersion 3.0
20:51:38 Verbose | PSRemotingProtocolVersion 2.3
20:51:38 Verbose | SerializationVersion 1.1.0.1
20:51:38 Info | hashtable back out
20:51:38 Info | plain
20:51:38 Info | System.Collections.Hashtable
20:51:38 Info | enum
20:51:38 Info | S
20:51:38 Info | y
20:51:38 Info | s
20:51:38 Info | t
20:51:38 Info | e
20:51:38 Info | m
20:51:38 Info | .
20:51:38 Info | C
20:51:38 Info | o
20:51:38 Info | l
20:51:38 Info | l
20:51:38 Info | e
20:51:38 Info | c
20:51:38 Info | t
20:51:38 Info | i
20:51:38 Info | o
20:51:38 Info | n
20:51:38 Info | s
20:51:38 Info | .
20:51:38 Info | H
20:51:38 Info | a
20:51:38 Info | s
20:51:38 Info | h
20:51:38 Info | t
20:51:38 Info | a
20:51:38 Info | b
20:51:38 Info | l
20:51:38 Info | e

Hi Tim,

Thanks for reaching out! You can’t pass full non-string objects as output variables using Set-OctopusVariable. But you can convert your hashtable into JSON, and then transform it back to a table when you use it on the next step.

Step 1

$foo=@{"a" = "aval";"b" = "bval";"c" = "cval"}
set-OctopusVariable -name Table -value ($foo | convertto-json)

Step 2

#The name of your variable will obviously be different
$OctopusParameters["Octopus.Action[CreateHashTable].Output.Table"] | convertfrom-json

Hope that helps!
Dalmiro

Didn’t think of that, fantastic idea, it looks like that will work.
Thanks
tim