Output Variable cannot be used in the next deployment step

Hi!
I appreciate all your help on my previous questions!

I have two windows service packages I am deploying at once: NSQd and Nsqlookupd. Nsqlookupd is installed first on a machine with role “Nsqlookupd”. After that, I have a powershell script step called “getlookupdAddress” which returns ip address of the machine i just deployed NSQLookupd to. PS script looks like this:

$tcp_port = “:4160”
$lookup_url = [System.Net.Dns]::GetHostAddresses("$($OctopusParameters[‘Octopus.Machine.Hostname’])")
$lookup_url = “$lookup_url”.Substring(4)
$lookupd = $lookup_url+$tcp_port
Set-OctopusVariable -name “Lookupd” -value “$lookupd”

I checked and returns: 10.164.28.190:4160 - exactly what i need

I did it after reading about Output variables, and thought I would use the output in the next deployment step called “Install NSQD”, because NSQD service needs an IP address of the machine where NSQLookupd is running.

So I use the output variable as an argument to run the NSQD service as part of the deployment step:

-mem-queue-size=0 -lookupd-tcp-address= $OctopusParameters[“Octopus.Action[GetLookupdAddress].Output.Lookupd”]

But, it does not work as expected, and does not recognize it as a system or output variable. Log looks like this:
sc.exe config B2B.Nsqd binPath= ““C:\b2b.nsq\services\nsqd.exe” -mem-queue-size=0 -lookupd-tcp-address=
#{$OctopusParameters[“Octopus.Action[GetLookupdAddress].Output.Lookupd”]}” DisplayName= “B2B.Nsqd” depend= / start= auto
[SC] ChangeServiceConfig SUCCESS

Am I doing it completelt wrong? Could you give me some direction on how to use that output variable?

Thanks a lot,

Aizhuldyz

Hi Aizhuldyz,

Thanks for reaching out. Coul you please enable these debugging variables in your project, then create a new release (so the new variables take effect) and send us a raw deployment log?

This will help us understand which variables are available at which point in your deployment.

Thanks!

Dalmiro

Hi Dalmiro,

Thanks for a quick reply! I looked at the raw log and was able to see the available variables. So I used
-lookupd-tcp-address=#{Octopus.Action[Install NsqLookupd].Output.Lookupd}
instead of using OctopusParameters:
#{$OctopusParameters[“Octopus.Action[GetLookupdAddress].Output.Lookupd”]}.
And now it works!

My another concern is how can I get IP addresses of all machines with a certain role and use it as an output variable in the next steps, in the above example I assumed I would only have one machine with a role NSQlookupd.

Thanks,

Aizhuldyz

Hi Aizhuldyz,

The way I’d recommend you to do it is by running your code snippet that gets the IP on each machine, and add an extra line to put that IP into a txt file. Then you’d import the content of the file from a Powershell step into a variable that is a full-blown array (instead of an Octopus variable that is just a plain string). Something like this:

Getting each ip

$tcp_port = ":4160" 
$lookup_url = [System.Net.Dns]::GetHostAddresses("$($OctopusParameters['Octopus.Machine.Hostname'])")
$lookup_url = "$lookup_url".Substring(4) 
$lookupd = $lookup_url+$tcp_port

$IPsFile = "c:\temp\Ips.txt" 

#Putting ip into txt file
$lookupd | out-file $IpsFile -append

Getting the IPs from the file

$IPs = get-content c:\temp\IPs.txt

#here do something with the IPs

#delete the file with the IPs at the end of the deployment
remove-item C:\Temp\IPs.txt -force -verbose

I’d also recommend you to use an Octopus variable for the full path of the IPs file to be able to use it from all the steps.

Hope that helps!

Dalmiro