Search code examples
yamlgithub-actions

Get only array element from a variable of github action


In github action file, I am running an AWS CLI command and storing the output of using set-ouput and reusing it in next step.

name: abc-name
id: abc
bash : |
   set-ouput name=opValue::$(aws ......command.....)

name: check
bash : echo ${{steps.abc.output.opValue}}

but the aws command's output is in the form of array like ["value"] and same is getting stored in variable opValue.

In my next "check step", I want to only fetch value of it, not the array.


Solution

  • Use jq to select the first value of the aws command output and store only that as output:

    set-ouput name=opValue::$(aws ......command..... | jq '.[0]')