Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Send parameter into custom GitHub action

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading