Issues passing output variables to subsequent steps

I am using a service account to run bash scripts to network servers (no tentacle). I have been trying to pass output variables from one step to another with varying results.
Do linux output variables get deleted when the calamari encounters a different exit code other than 0? Because i am witnessing different results when using the “set-octopusvariable” command in bash. Half of the time, the variable is not transferred to the subsequent step where the “get-octopusvariable” function is used.

Thank you very much for your time,
Victor

Hi @victor-marian.ion

Thanks for reaching out, and sorry to hear that you’re having issues here - I just spun up a local reproduction of this, but it always appears to write the output variable so it’s accessible for the next step. Here’s my setup, please let me know how the logic flow compares to what you’re trying to achieve:

Step 1 (Run a script step, blah does not exist, which will throw an error and cause the step to fail):

echo "Setting Variable"
set_octopusvariable "Var" "123456"
cat blah

Step 2 (Run a script step, configured to run always):

myString=$(get_octopusvariable "Octopus.Action[SetVariable].Output.Var")
echo "Variable is: $myString"

This works consistently on my end, with it working as expected over 20 deployments.

I hope this helps, and please let me know if this lines up with what you’re attempting to do, and if you have any further questions.

And just to make sure i understand, each separate step is a new shell in Linux. For instance, if i use a variable for the step name

> stepName="This is my step name 1"
> myString=$(get_octopusvariable "Octopus.Action[$stepName].Output.Var")
> echo "Variable is: $myString"

and i run multiple process steps with this script structure

> stepName="This is my step name 2"
> myString=$(get_octopusvariable "Octopus.Action[$stepName].Output.Var")
> echo "Variable is: $myString"

> stepName="This is my step name 3"
> myString=$(get_octopusvariable "Octopus.Action[$stepName].Output.Var")
> echo "Variable is: $myString"

each step will get the variable set in the each declaration step (1,2,3), regardless of sudo commands?

Hi @victor-marian.ion

You’re correct, each step is a new child bash process.

Your example there should work fine, I still had my original reproduction project here, so I updated it to show you how I did it:

Step 1 - Name = SetVariable (cat blah will fail)

echo "This PID is $BASHPID"
echo "Setting Variable"
set_octopusvariable "Var" "123qwe"
cat blah

Step 2 - Name = SetVariable2 (set to always run, since SetVariable will error out).

echo "This PID is $BASHPID"
echo "Setting Variable"
set_octopusvariable "Var" "qwe123"

Step 3 - Name = ReadVariable (set to always run, for the same reason)

echo "This PID is $BASHPID"

stepName="SetVariable"
myString=$(get_octopusvariable "Octopus.Action[$stepName].Output.Var")
echo "Variable for $stepName is: $myString"

stepName="SetVariable2"
myString=$(get_octopusvariable "Octopus.Action[$stepName].Output.Var")
echo "Variable for $stepName is: $myString"

This produces an output of:

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