1

Is there is the way to pass variable with "map type" ?

For example is it possible to do something like below:

jobs:
  docker_build_and_push:
  uses: test/test/.github/workflows/matrixDocker.yml@main
  with:
    # Docker image name
    service_name: nesso
    tags: {"nginx":"new", "api":"old"}         <<<<<<    ????

2 Answers 2

2

Unfortunately, this is not possible yet. As I wrote in a previous answer, the only supported input types for actions are string | number | boolean (schema: with ref: definitions/env).

So the workaround would be either you pass multiple arguments to your action, or you pass them as a JSON string then you parse it with jq (if your action uses shell/bash).


And here are these example workarounds:

Specify more options as inputs to your action

Simply add more inputs to your action instead of one input of type map:

name: 'Hello World'
description: 'Greet someone'
inputs:
  greeting-word:
    description: What to say
    required: false
    default: Hello
  who-to-greet:
    description: 'Who to greet'
    required: true
  something-else:
    description: Something else to say
    required: false
    default: ""
    

runs:
  using: "composite"
  steps:
    - name: Greet!
      shell: bash
      run: echo "${{ inputs.greeting-word }} ${{ inputs.who-to-greet }} ${{ inputs.something-else }}"

Then just pass them form your workflow file

  - name: Greet
    uses: ./.github/actions/my-action
    with:
      greeting-word: Hallo
      who-to-greet: Bob

Pass arguments as a JSON string

Workflow file:

  - name: Greet
    uses: ./.github/actions/my-action
    with:
      greeting-args: '{"greeting-word": "Hello", "who-to-greet": "Bob"}'

The action

name: 'Hello World'
description: 'Greet someone'
inputs:
  greeting-args:
    required: true
    description: Greeting arguments

runs:
  using: "composite"
  steps:
    - name: Greet!
      shell: bash
      run: |
        MY_INPUT='${{ inputs.greeting-args }}'
        GREETING_WORD=$(echo $MY_INPUT | jq -r '."greeting-word"')
        WHO_TO_GREET=$(echo $MY_INPUT | jq -r '."who-to-greet"')

        echo "${GREETING_WORD} ${WHO_TO_GREET}"

Or you can pass it as a multi-line string

This approach is used by actions like actions/upload-artifact

- uses: actions/upload-artifact@v3
  with:
    name: my-artifact
    path: |
      path/output/bin/
      path/output/test-results
      !path/**/*.tmp

And google-github-actions/get-secretmanager-secrets

- id: 'secrets'
  uses: 'google-github-actions/get-secretmanager-secrets@v1'
  with:
    secrets: |-
      token:my-project/docker-registry-token
      anotherOne:my-project/a-secret
      anotherOneToo:my-project/another-secret

i.e you just need to read these lines and split your map's key/values

Sign up to request clarification or add additional context in comments.

Comments

0

A matrix strategy allows map inputs so you can workaround this limitation like this

jobs:
  map-sample:
    name: Test map inputs
    runs-on: ubuntu-latest
    strategy:
      matrix:
        configuration: [{tags: {nginx: "new", api: "old"}, service_name: "nesso"}]

    steps:

      - name: Check Inputs
        run: |
          echo "Inputs are Nginx: ${{ matrix.configuration.tags.nginx }} API: ${{ matrix.configuration.tags.api }}"
          echo "Service: ${{ matrix.configuration.service_name }}"

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.