My workflow needs to receive 2 input parameters from the user. Valid values of those parameters are defined by a separate script. These values can change (not able to hard code them) so I want to populate the list dynamically when the job is to be run. The picker should update according to the result of the script allowing the user to select and only then should the actual job be run with those values as input to the job
How to provide a drop down like that?
Since Nov. 2021, the input type can actually be a choice list.
GitHub Actions: Input types for manual workflows
You can now specify
inputtypes for manually triggered workflows allowing you to provide a better experience to users of your workflow.
In addition to the defaultstringtype, we now supportchoice,boolean, andenvironment.
name: Mixed inputs
on:
workflow_dispatch:
inputs:
name:
type: choice
description: Who to greet
options:
- monalisa
- cschleiden
message:
required: true
use-emoji:
type: boolean
description: Include 🎉🤣 emojis
environment:
type: environment
jobs:
greet:
runs-on: ubuntu-latest
steps:
- name: Send greeting
run: echo "${{ github.event.inputs.message }} ${{ fromJSON('["", "🥳"]')[github.event.inputs.use-emoji == 'true'] }} ${{ github.event.inputs.name }}"
That would provide a dropdown.
The question remains: can you pass a list of choices as variable to your input choice field?
You should, if you can populate the inputs context, through another job (computing your list), and calling your choice job, passing the list through jobs.<job_id>.with / jobs.<job_id>.with.<input_id>
Let's say I have my 'deploy' job with 'workflow_dispatch' inputs. I'll add a new 'preparation' job, which will generate a relevant choice list. But how I'll be able to call 'deploy' job manually after 'preparation' job?
Since the options are statically defined with the on.workflow_dispatch.inputs, type choice, this is not yet supported.
It was requested in this discussion:
Rather than the existing feature requests to have (filtered) tags (or branches) as choice options for a manual workflow trigger, ideally GitHub Actions would support to run a piece of code, possibly through a pre-trigger action, to populate one ore more options for the manual trigger.
One use case for pre-trigger actions could be to fill a (filtered) list of tags and/or branches.
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