Github action how to access the inputs

Viewed 2707

enter image description here

on: 
  workflow_dispatch:
    inputs:
      logLevel:
        description: 'Log level'     
        required: true
        default: 'warning'
      tags:
        description: 'Test scenario tags'

I have the following inputs:

  • Which branch do I want to use
  • Input fields

How do I access the information that I enter and then use it later in the github action script?

2 Answers

To use an input from the workflow_dispatch trigger on your yaml file, you need to use the following syntax ${{ github.event.inputs.<input_name> }} or ${{ inputs.<input_name> }}.

For example, in your case:

on: 
  workflow_dispatch:
    inputs:
      logLevel:
        description: 'Log level'     
        required: true
        default: 'warning'
      tags:
        description: 'Test scenario tags'

jobs:
  printInputs:
    runs-on: ubuntu-latest
    steps:
    - run: |
        echo "Log level: ${{ github.event.inputs.logLevel }}"
        echo "Tags: ${{ github.event.inputs.tags }}" 

Here is a simple demo if you want to check:

You can also check the official documentation about it.

You now (June 2022) have an alternative:

You could try and take advantage of a new feature (June 2022)

GitHub Actions: Inputs unified across manual and reusable workflows

Workflows triggered by workflow_dispatch and workflow_call can now access their inputs using the inputs context.

Previously workflow_dispatch inputs were in the event payload.
This made it difficult for workflow authors who wanted to have one workflow that was both reusable and manually triggered.

Now a workflow author can write a single workflow triggered by workflow_dispatch and workflow_call and use the inputs context to access the input values.

For workflows triggered by workflow_dispatch, inputs are still available in the github.event.inputs context to maintain compatibility.

Using the inputs context in GitHub Actions.

In your case:

jobs:
  printInputs:
    runs-on: ubuntu-latest
    steps:
    - run: |
        echo "Log level: ${{ inputs.logLevel }}"
        echo "Tags: ${{ inputs.tags }}" 
Related