Workflow_dispatch and schedule with inputs

For the workflow_dispatch I defined some inputs, and would like the schedule to run with the same defaults, but the {{ github.events.inputs.(field) }} is empty.

Is there any way to make these two events use the same data?

name: Some Workflow

on:
  schedule:
    - cron:  '0 4 3 * *'
  workflow_dispatch:
    inputs:
      an_input:
        description: 'Input?'
        required: true
        default: 'Foo'
jobs:
  build:
  # Do something with ${{ github.event.inputs.an_input }}

(updated to better express the ask)

1 Like

Should they both always use the same values?

https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#inputs

So you’ve already got something like:

name: Some Workflow

on:
  workflow_dispatch:
    inputs:
      an_input:
        description: 'Input?'
        required: true
        default: 'Foo'
jobs:
  build:
  # Do something with ${{ github.event.inputs.an_input }}
name: Some Workflow

on:
  schedule:
    - cron:  '0 4 3 * *'
    inputs:
      an_input:
        description: 'Input?'
        required: true
        default: 'Foo'
  workflow_dispatch:
    inputs:
      an_input:
        description: 'Input?'
        required: true
        default: 'Foo'
jobs:
  build:
  # Do something with ${{ github.event.inputs.an_input }}

I haven’t tested but I suspect that you can likely also do something like:

name: Some Workflow

inputs:
  an_input:
    description: 'Input?'
    required: true
    default: 'Foo'

on:
  schedule:
    - cron:  '0 4 3 * *'
  workflow_dispatch:

jobs:
  build:
  # Do something with ${{ github.event.inputs.an_input }}

I haven’t tried either of the later two since the documentation doesn’t mention that as an option. I’ve barely even seen a reference to the original workflow_dispatch.

I guess I could try them as an option

Okay, so I just tried both of those recommendations and neither of them are valid syntax for the actions file. So unless there is some other way to do this, I guess the best option is to do two different workflows that do exactly the same thing but have different triggers.

I’ll do some testing tomorrow. Hopefully I just bungled something silly.

Hi @ajohnson-ventera Thanks for your feedback.

Seems to be impossible with my knowledge. Different event names correspond to different Webhook event payloads.
If the work flow is triggered by workflow_dispatch
this Webhook payload will be appended in the Github Context. So you can use the ${{ github.event.inputs.an_input }} in your work flow.


here is the log to show the the Github Context demonstrating this.

If the work flow is triggered by schedule
There is no Webhook payload(only “schedule”: “*/15 * * * *”) can be attached to Github Context. So this is why you cannot use the {{ github.events.inputs.(field) }}

If the values are static, then you could just use env and do something like:

name: Test2

on:
  schedule:
    - cron:  '*/5 * * * *'
  workflow_dispatch:

jobs:
  Test2:
    env:
      AN_INPUT: Foo
    name: Test2
    runs-on: ubuntu-latest
    steps:
    - name: Test2
      run: |
        echo $AN_INPUT
        exit 0

If you want workflow_dispatch to be able to override the values you could do something like:

name: Test2

on:
  schedule:
    - cron:  '*/5 * * * *'
  workflow_dispatch:
    inputs:
      an_input:
        description: 'Input?'
jobs:
  Test2:
    env:
      AN_INPUT: Foo
    name: Test2
    runs-on: ubuntu-latest
    steps:
    - name: Step 1
      if: github.event.inputs.an_input != ''
      run: echo "::set-env name=AN_INPUT::${{ github.event.inputs.an_input }}"
    - name: Step 2
      run: |
        echo $AN_INPUT
        exit 0

So if the input isn’t empty then it overrides the env variable.