inputs are available to workflows triggered by the workflow_dispatch event only (and to any workflows that are called by dispatched workflows).
When a workflow with inputs is triggered on a schedule (or on push/pull) all the input values are null. Any defaults that are set in the inputs section have no effect.
Therefore you need to set the defaults at the point where they are needed in the workflow. A convenient method for doing this uses Github expressions.
For string and choice inputs you can use the || expression operator to set the default value.
For boolean inputs that default to false you can use || expression to set the default value.
For boolean inputs that default to true you can use the contains() function to set the default value.
For example:
on:
schedule:
- cron: '15 0,18 * * 0-5'
workflow_dispatch:
inputs:
springProfile:
required: true
type: choice
options:
- staging
- production
logLevel:
required: true
type: string
isFalseWhenScheduled:
required: true
type: boolean
isTrueWhenScheduled:
required: true
type: boolean
jobs:
test:
uses: ./.github/workflows/run-job-with-params.yml
secrets: inherit
with:
springProfile: ${{ inputs.springProfile || 'staging' }}
logLevel: ${{ inputs.logLevel || 'DEBUG' }}
isFalseWhenScheduled: ${{ inputs.isFalseWhenScheduled || false }}
isTrueWhenScheduled: ${{ !contains(inputs.isTrueWhenScheduled, 'false') }}
In the above example, if the workflow is triggered on schedule:
- the
springProfile parameter is set to 'staging'.
- the
logLevel parameter is set to 'DEBUG'.
- the
isFalseWhenScheduled parameter is set to false
- the
isTrueWhenScheduled parameter is set to true
If the job is triggered on workflow_dispatch: then the above parameters are set to the inputs: values.
Boolean value defaults
The contains function casts its first parameter to a string, and null is cast to the empty string ''. As mentioned, when triggered on schedule, inputs parameters are all set to null.
So:
| Trigger method |
isTrueWhenScheduled value |
input value resolves to |
| workflow_dispatch |
true |
!contains('true', 'false') = true |
| workflow_dispatch |
false |
!contains('false', 'false') = false (*) |
| schedule |
null |
!contains('', 'false') = true |
(*) This combination is what necessitates the use of contains. If contains is not used and you do ${{ inputs.isTrueWhenScheduled || true }} this will force this value to true even if it is set false in the workflow dispatch event.
And:
| Trigger method |
isFalseWhenScheduled value |
input value resolves to |
| workflow_dispatch |
true |
true || false = true |
| workflow_dispatch |
false |
false || false = false |
| schedule |
null |
null || false = false |