I have a workflow that is triggered by workflow_dispatch events with a few non-required string inputs and am trying to figure out how to determine if the value was provided or not.
on:
workflow_dispatch:
inputs:
input1:
description: first input
required: false
type: string
input2:
description: second input
required: false
type: string
The documentation says that unset inputs that are of type string will be equated to an empty string in the workflow but when I check that in an if clause condition for a job, it doesn't seem to be evaluating properly.
jobs:
jobA:
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.input1 != '' }}
# ...
Even when I dispatch the workflow with the input empty, both steps are ran.
What is the idiomatic way of checking if an input value was unset or not if this is not it?
You don't need the ${{ }} in this case, just using:
if: github.event_name == 'workflow_dispatch' && github.event.inputs.input1 != ''
Will work
name: Test 35 # Related to https://stackoverflow.com/questions/72379994/github-actions-check-empty-dispatch-input
on:
workflow_dispatch:
inputs:
input1:
description: first input
required: false
type: string
input2:
description: second input
required: false
type: string
jobs:
jobA:
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch' && github.event.inputs.input1 != ''
steps:
- run: echo "Input 1 not empty"
jobB:
runs-on: ubuntu-latest
if: github.event_name != 'workflow_dispatch' || github.event.inputs.input1 == ''
steps:
- run: echo "Input 1 is empty"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With