binh.au
(binh.au)
February 17, 2017, 10:52am
1
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 }
Dalmiro
(Dalmiro Grañas)
February 17, 2017, 11:30am
2
Hi,
Thanks for reaching out. Totally possible. We call those Output Variables: https://octopus.com/blog/fun-with-output-variables
Hope that helps!
Dalmiro
binh.au
(binh.au)
February 20, 2017, 2:14pm
3
further question. Can the step variable be change by another step?
Dalmiro
(Dalmiro Grañas)
February 21, 2017, 2:42pm
4
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