My idea here is to write my inputs from workflow_dispatch on each pipeline run. .
For example, in Bitbucket pipelines input parameters shown after custom -
Is there a way to do something similar for GitHub?
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"
}
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.
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.
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:
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
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"
}
],
© 2022 - 2024 — McMap. All rights reserved.
inputs
context forworkflow_dispatch
help you access those values? – Billingsley