Schedule Trigger Github Action workflow with Input parameters

Viewed 779

I want to run my Github workflow two ways:

  1. Manually by user
  2. Cron job

Now, everything was running fine until I added input parameters. After that, the cron job is running but not picking default value.

Here is my yaml:

name: WebDriverIO Automation
on:
  workflow_dispatch:
    inputs:
        typeOfTesting:
          type: choice
          description: Select Type of Test
          default: 'stage-test-local-All'
          required: true
          options: 
          - stage-test-local-All
          - stage-test
          - stage-test-local-Sanity
          - prod-test
    branches:
      - workingBranch
      - JSNew
  schedule:
    - cron: "*/5 * * * *"
2 Answers

Below code worked

name: WebDriverIO Automation
on:
  workflow_dispatch:
    inputs:
        typeOfTesting:
          type: choice
          description: Select Type of Test
          default: 'stage-test-local-All'
          required: true
          options: 
          - stage-test-local-All
          - stage-test
          - stage-test-local-Sanity
          - prod-test
    branches:
      - workingBranch
  schedule:
    - cron: "*/5 * * * *"

...
..
..
   - name: Test
        run: |
          if [ ${{ github.event.inputs.typeOfTesting }} != "" ]; then
            npm run ${{ github.event.inputs.typeOfTesting }} 
          else 
              npm run stage-test-local-All 
          fi

inputs are available to workflows triggered by the workflow_dispatch event only (and to any workflows that are called by dispatched workflows).

You can use the || expression operator to set the default values for input parameters. For example:

on:
  schedule:
    - cron: '15 0,18 * * 0-5'
  workflow_dispatch:
    inputs:
      logLevel:
        required: true
        type: string

jobs:
  test:
    uses: ./.github/workflows/run-job-with-params.yml
    secrets: inherit
    with:
      springProfile: 'production'
      logLevel: ${{ inputs.logLevel || 'DEBUG' }}

In the above example the logLevel parameter is set to DEBUG when the workflow is triggered by cron. When the job is triggered by a dispatch event it gets set to the input value.

Related