11

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?

voralexan
  • 131
  • 1
  • 1
  • 7
  • Would the [new `inputs` context for `workflow_dispatch`](https://stackoverflow.com/a/72576146/6309) help you access those values? – VonC Jun 10 '22 at 14:46

6 Answers6

14

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"
}
Jon Peterson
  • 723
  • 7
  • 21
6

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.

briancaffey
  • 2,339
  • 6
  • 34
  • 62
3

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.

Lee Netherton
  • 21,347
  • 12
  • 68
  • 102
  • 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 access – blast_hardcheese Jun 09 '23 at 23:20
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:

Grzegorz Krukowski
  • 18,081
  • 5
  • 50
  • 71
  • 2
    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. – Derek Greer Apr 13 '22 at 17:32
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

YBadiss
  • 234
  • 3
  • 5
0

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"
  }
],
Josh Johanning
  • 840
  • 9
  • 16