0

I'm familiar with Active choice parameters plugin in Jenkins to build dynamic UI.

Upon selection of one paramter the second paramter is dynamically populated.

I'm new to github actions, but wanted to know if it is possible to achieve something like below.

List Dropdown 1 multi-select having below options

Color
Fruit

If Color is selected Dynamic Dropdown 2 will show:

Green
Blue
Red

If Fruit is selected:

Apple
Orange

If both Color and Fruit are selected:

Green
Blue
Red
Apple
Orange

Kindly suggest.

Ashar
  • 2,942
  • 10
  • 58
  • 122

1 Answers1

0

actions/runner issue 998 is an example of such a need for dynamic input, but was closed.

You have different approaches illustrated here to emulate that feature, but you can also try, using "GitHub Actions: Input types for manual workflows":

  • adding a config file to your repository
  • read values from that files depending on your choice.

The config file: dynamic_options.json:

{
  "Color": ["Green", "Blue", "Red"],
  "Fruit": ["Apple", "Orange"]
}

And your workflow script:

name: Dynamic Dropdown Workflow

on:
  workflow_dispatch:
    inputs:
      list_1:
        typoe: choice
        description: 'Select options:'
        required: true
        default: 'Color'
        options: 
        - Color
        - Fruit
      list_2:
        description: 'Select dynamic options:'
        required: true
        default: ''

jobs:
  dynamic-dropdown:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2

      - name: Install jq
        run: |
          sudo apt-get update
          sudo apt-get install jq

      - name: Retrieve dynamic options
        id: get_dynamic_options
        run: |
          IFS=',' read -ra INPUT_OPTIONS <<< "${{ github.event.inputs.list_1 }}"
          DYNAMIC_OPTIONS=""
          for option in "${INPUT_OPTIONS[@]}"; do
            OPTION_VALUES=$(jq ".$option | join(\",\")" dynamic_options.json --raw-output)
            if [ -n "$DYNAMIC_OPTIONS" ] && [ -n "$OPTION_VALUES" ]; then
              DYNAMIC_OPTIONS+=","
            fi
            DYNAMIC_OPTIONS+="$OPTION_VALUES"
          done
          echo "DYNAMIC_OPTIONS=$DYNAMIC_OPTIONS" >> $GITHUB_ENV

      - name: Use dynamic options
        run: |
          echo "Selected options from List 1: ${{ github.event.inputs.list_1 }}"
          echo "Selected options from List 2: $DYNAMIC_OPTIONS"
          # Continue with your workflow steps using the dynamic options
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250