Passing variables within workflow - Powershell

Hi Harness experts.
I am trying to preserve some variables to workflow, so I can use them later in rollback step. However I haven’t had luck. I used workflow variable first, but I couldn’t assign values to it in powershell. It was not letting me set value for ${workflow.variables.test} saying it couldn’t find test in workflow.variables.

Then I tried using this article: Pass Variables between Workflows - Docs
But export command doesn’t work in powershell. The examples in above article are all BASH scripts. I tried with return instead, and still nothing. No luck. Any ideas?

Hey @Monte_Albert,

The first thing I would recommend is actually wrapping the variable in double quotes.

For example ${workflow.variables.test} should be "${workflow.variables.test}". The Workflow Variables are available throughout the entirety of the workflow, including the rollback, so that shouldn’t be an issue.

The next thing to think about with Workflow Variables is that they are only usable in the workflow which they are instantiated for. If you would like a variable from one workflow to pass into an entirely different workflow, they will need to be in a pipeline and the variable will need to be created and populated via a Context Variable instead: Run Shell Scripts in Workflows - Docs

One way to turn a Workflow Variable into a Context Variable is to leverage a Shell Script in the Workflow:
export CONTEXT=$(echo "${workflow.variables.test}") and then leverage the link above to pass it to the rest of the pipeline.

Let me know if you have any questions!

1 Like