Home > Software engineering >  Send parameter into custom GitHub action
Send parameter into custom GitHub action

Time:10-14

What specific syntax must be changed in the code below in order to successfully pass a parameter into the GitHub custom action from the GitHub workflow?

The workflow file code is at .github/workflows/mycustomworkflow.yml and contains the code:

name: send-param-into-custom-action
on:
  push:
    branches:
      - dev
jobs:
  send-the-param:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - id: SendParamIntoCustomAction
        uses: ./.github/actions/my-custom-action
        with:
          custom_param: "Some literal string"

The GitHub action file is at .github/actions/my-custom-action/action.yml and contains the code:

name: 'Pass a parameter into a custom action'
description: 'Receives a parameter and prints it out.'
runs:
  using: "composite"
  steps:
    - shell: bash
      name: Print the parameter value
      env:
        custom_param: ${{ inputs.custom_param }}
      run: |
        echo 'About to echo the parameter value'
        echo $custom_param

CodePudding user response:

You need an inputs object in the metadata file:

name: Pass a parameter into a custom action
description: Receives a parameter and prints it out.

inputs:
  custom_param:
    description: Custom input parameter
    required: true

runs:
  using: composite
  steps:
    - shell: bash
      name: Print the parameter value
      env:
        custom_param: ${{ inputs.custom_param }}
      run: |
        echo 'About to echo the parameter value'
        echo "$custom_param"
  • Related