Search code examples
ubuntuyamlgithub-actions

Set output of step as array


I'm getting a list of feature/* branches from my repository in a GitHub action using:

echo ::set-output name=branches::$( git branch -r | grep -i "feature/" | sed -e "s/.*origin\///" | tr "\n" " " )

However, this list is String output and I need it in a String array so I can use it to call another workflow using the Matrix strategy.

I've tried numerous tactics including:

  • wrapping the expression in () which results in a syntax error ("unexpected token: (")
  • using an environment variable which results in an empty string with or without wrapping the expression in ()
  • using a local variable which results in different outcomes depending on how I assign it. In my dev environment, I have 2 feature branches (feature/quality-3 and feature/test-feature)

using:

branches=($( git branch -r | grep -i "feature/" | sed -e "s/.*origin\///" | tr "\n" " " ))

with:

echo ::set-output name=branches::${branches[@]} # also ${branches[*]}

gives an error with both values: "Unexpected type of value 'feature/quality-3 feature/test_feature', expected type: Sequence."

with:

echo ::set-output name=branches::${branches} # or $branches

gives an error with 1 value: "Unexpected type of value 'feature/quality-3', expected type: Sequence."


Solution

  • You have to pass such data as a JSON between jobs:

    Use combination of:

    Here is a full example from GitHub.