Bart Krakowski
Bart Krakowski

Reputation: 1670

Passing object as a variable to Github action

How can I pass an additional object type variable? When I try to do this in the yaml file a get an error:

Invalid type found: one of string , number , boolean were expected but an array was found


on: pull_request_review
name: Label approved pull requests
jobs:
  labelWhenApproved:
    name: Label when approved
    runs-on: ubuntu-latest
    steps:
    - name: Label when approved
      uses: ***
      env:
        APPROVALS:
          - value: "1"
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        ADD_LABEL: "approved"
        REMOVE_LABEL: "awaiting%20review"

Upvotes: 2

Views: 12850

Answers (2)

Andrew Eisenberg
Andrew Eisenberg

Reputation: 28757

This is a bit of an old question and you've probably found some sort of workaround, but here is an option for you. This is what we do when we need to pass an object into a string input:

      env:
        APPROVALS: |
          - value: "1"

The | converts the next block into a multi-line string. Everything until the next outdentation is a string.

What this means is that your action *** must then use a yaml parser to convert from the string to an object.

Upvotes: 3

Denis Duev
Denis Duev

Reputation: 611

The env: section allows you to pass Environment Variables to the actions. The environment variables are key - value. You cannot pass objects.

From GitHub docs:

A map of environment variables

In some cases you can "stringify" a whole object and pass it as an environment variable using toJSON(), but the action itself should "know" how to handle it (e.g to parse the object from the string)

Example how to pass all secrets to an actions:

  env:
    SECRETS: '${{ toJSON(secrets) }}'

Note: There can be env in different levels in the workflows - you can have them on "global", on a job, or on step (in your case it is a step)

Upvotes: 3

Related Questions