GitHub Actions: How to view inputs for workflow_dispatch?
Asked Answered
K

6

14

My idea here is to write my inputs from workflow_dispatch on each pipeline run. ![enter image description here.

For example, in Bitbucket pipelines input parameters shown after custom - enter image description here

Is there a way to do something similar for GitHub?

Killy answered 17/2, 2022 at 9:39 Comment(1)
Would the new inputs context for workflow_dispatch help you access those values?Billingsley
T
17

Although this does not directly answer your question, I'm adding it here because this is where I landed looking for the answer on how to output all my workflow inputs.

In my case I am using a workflow_dispatch trigger - YMMV if you are using a different trigger, but I suspect it would work the same way.

As with the other answer proposed, you will need to do this as a step within your job:

on:
  workflow_dispatch:
    inputs:
      myInput:
        default: "my input value"
jobs:
  myJob:
    steps:
      - name: Output Inputs
        run: echo "${{ toJSON(github.event.inputs) }}"

This will result in output you can view in your GitHub action execution output with the inputs serialized as JSON:

{
  "myInput": "my input value"
}
Thalassic answered 11/5, 2022 at 18:23 Comment(0)
C
15

You can use the run-name parameter to change the name of the run in the actions list:

Example of run-name

run-name: Deploy to ${{ inputs.deploy_target }} by @${{ github.actor }}

Be aware that, if you are using Github Enterprise server, this parameter was introduced in version 3.8.

Chameleon answered 27/2, 2023 at 9:54 Comment(1)
Holy moly, I've been looking for this for over a year! I had just resigned myself to it not being possible without direct API accessHipbone
D
9

If you have only a few simple input values (from workflow_dispatch) then you can include them in the name of the job:

on:
  workflow_dispatch:
    inputs:
      my_value:
        description: 'My input value'
        required: true
        default: 'foo'
        type: string

jobs:
  my_job:
    name: "My job [my_value: ${{ github.event.inputs.my_value }}]"
    runs-on: ubuntu-latest

    steps:
    ....

This way you will be able to see the input directly in the GitHub UI.

Dunkle answered 25/5, 2022 at 13:27 Comment(1)
In lieu of them allowing the actual name to be changed this has been a life saver. Thanks!Polonium
T
1

You cannot really alter how they will be displayed on the list I'm afraid.

All you can do is to log your input variables inside action itself, like this:

jobs:
  debugInputs:
    runs-on: ubuntu-latest
    steps:
    - run: |
        echo "Var1: ${{ github.event.inputs.var1 }}"
        echo "Var2: ${{ github.event.inputs.var2 }}" 

If you want to see them in summary, you can use a notice or warning message mark:

Tinnitus answered 18/2, 2022 at 11:2 Comment(1)
Well this is quite the oversight on the part of the github team. The setup job node should most definitely include any input variables used, otherwise there is no way to really prove what values were used for a given job.Leticia
M
1

I was looking for something similar and landed on logging + writing to the Job Summary.

I created a small action that can easily be used as a first step in your workflow, since I found myself need

Mujik answered 27/10, 2022 at 14:33 Comment(0)
A
1

It's probably easiest to set the run-name of the workflow and parse that for workflow_dispatch inputs.

But, if you want to retrieve the workflow_dispatch objects for workflows that have already been ran, the data is only available in the logs.

Admittedly a little hacky, but this script does just that (loops through a list of workflow runs, downloads/extracts logs, and uses sed to extract the inputs): https://github.com/joshjohanning/github-misc-scripts/blob/main/gh-cli/get-workflow-dispatch-inputs.sh

This will return something such as:

[
  {
    "workflowName": "workflow-b",
    "workflowId": "5870059990",
    "inputs": {
      "animal": "bee",
      "color": "orange",
      "food": "avocado"
    },
    "createdAt": "2023-08-15T17:45:21Z",
    "conclusion": "success"
  }
],
Aristaeus answered 15/8, 2023 at 20:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.