Carrying Variable value across Steps

Hi,

Just out of curiosity, is it possible to have a powershell step that set a Variable that are then picked up by another powershell step within the same process.

e.g.
Step 1
$Test += ‘India’

Step 2
$Test += ‘UK’

Step 2
Foreach ($item in $Test){ $Item }

Hi,

Thanks for reaching out. Totally possible. We call those Output Variables: https://octopus.com/blog/fun-with-output-variables

Hope that helps!
Dalmiro

further question. Can the step variable be change by another step?

Hi,

I totally misinterpreted your initial email even though it was super clear. Apologies for that.

What you want to do isn’t 100% possible with Octopus variables, but you can work your way arround it like this:

Step1

$TempTextFile = ".\temp.txt" #The script root path will be the temp
if(!(Test-Path $TempTextFile)){
    New-Item $TempTextFile -ItemType File
}

[string[]] $test = Get-Content $TempTextFile
[string[]] $test += "India"
Set-Content -Value $test -Path $TempTextFile

Step2

$TempTextFile = ".\temp.txt"
if(!(Test-Path $TempTextFile)){
    New-Item $TempTextFile -ItemType File
}

[string[]] $test = Get-Content $TempTextFile
[string[]] $test += "India"
Set-Content -Value $test -Path $TempTextFile


Step3 (or any other Powershell step where you wanna use the info gathered through the other steps)

$TempTextFile = ".\temp.txt"
$test = Get-Content $TempTextFile
foreach($entry in $test){
    $entry
}

I recommend you to use an Octopus project variable to set the value of $TempTextFile

Hope that helps,

Dalmiro