How to pass output of my ps script to a octopus variable, so that I can pass the variable as input to my next step

Hi,

Below script gives me list of IPs. I want to store them in a octopus variable. So that I can pass the variable to my next step as input. If its not possible then what is the best way to pass this list of output to my next step.

$vnet = Get-AzureRmVirtualNetwork -Name “XXXXXXXXX” -ResourceGroupName “YYYYYYYYY”
$networkID = “10.0.0.”
$vhd1_ip_list = new-object System.Collections.Arraylist
$j = 0
For ($I=1; $i -lt 5; $i++)
{
$IP = $networkID + $i
$Address = Test-AzureRmPrivateIPAddressAvailability -VirtualNetwork $vnet -IPAddress $IP
If ($Address.Available –eq $False) { Write-Host “$IP is not available” -ForegroundColor Red
$vhd1_ip_list.Add($IP)
$j++
}
else { Write-Host “$IP is available” -ForegroundColor Green}
}
$available_ips = @(Foreach ($a in $vhd1_ip_list)
{
Write-Host $a
})
Write-Host $available_ips

Regards,
-Siva

Greetings Siva! Octopus Deploy supports the use of Output Variables, see https://octopus.com/docs/deployment-process/variables/output-variables for documentation on how to use this.

Hope this helps!

Thanks for your quick response.

I have gone through his…this is what I did and please correct me if I’m doing it incorrect

step 1:

$vnet = Get-AzureRmVirtualNetwork -Name “XXXXXXXXX” -ResourceGroupName “YYYYYYYYY”
$networkID = “10.0.0.”
$vhd1_ip_list = new-object System.Collections.Arraylist
$j = 0
For ($I=1; $i -lt 5; $i++)
{
$IP = $networkID + $i
$Address = Test-AzureRmPrivateIPAddressAvailability -VirtualNetwork $vnet -IPAddress $IP
If ($Address.Available –eq $False) { Write-Host “$IP is not available” -ForegroundColor Red
$vhd1_ip_list.Add($IP)
$j++
}
else { Write-Host “$IP is available” -ForegroundColor Green}
}
$available_ips = @(Foreach ($a in $vhd1_ip_list)
{
Write-Host $a
})
Write-Host $available_ips
Set-OctopusVariable -name “available_ips” -value “Passed”

step 2:

Write-Host “Printg from IP availability step”
$available_ips = $OctopusParameters[“Octopus.Action[ip availability].Output.available_ips”]
Write-Host $available_ips

regards,
-Siva

May I assume the name of step 1 is ip availability? Since it has a space in the name, you may need to surround it with single quotes.

I tried changing that…but it still doesn’t print the values which are stored in $available_ips in step 2

step 1:

$vnet = Get-AzureRmVirtualNetwork -Name “XXXXXXXXX” -ResourceGroupName “YYYYYYYYY”
$networkID = “10.0.0.”
$vhd1_ip_list = new-object System.Collections.Arraylist
$j = 0
For ($I=1; $i -lt 5; $i++)
{
$IP = $networkID + $i
$Address = Test-AzureRmPrivateIPAddressAvailability -VirtualNetwork $vnet -IPAddress $IP
If ($Address.Available –eq $False) { Write-Host “$IP is not available” -ForegroundColor Red
$vhd1_ip_list.Add($IP)
$j++
}
else { Write-Host “$IP is available” -ForegroundColor Green}
}
$available_ips = @(Foreach ($a in $vhd1_ip_list)
{
Write-Host $a
})
Write-Host $available_ips
Set-OctopusVariable -name “available_ips” -value $available_ips

step 2:

Write-Host “Printg from IP availability step”
$available_ips = $OctopusParameters[“Octopus.Action[ipavailability].Output.available_ips”]
Write-Host $available_ips

Regards,
-Siva

Thanks, I figured it out.

Excellent! Please let me know if I can be of further assistance :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.