How to pass parameters to Github Actions Workflow #27002
-
hi folks I have bunch of parameterized Jenkins jobs, saying before starting the build, the user can input the params for the job. i’m looking for similar feature for Github Actions for our deployment job which listen on github deployment event. for example, i’d like to allow user to be able to turn on/off some flags of the deployment, looks like the github deployment api support payload with any value like a json string: https://developer.github.com/v3/repos/deployments/#create-a-deployment can the Github Actions receive that deployment payload and extract values for the workflow? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Hi @missedone , I am not sure whether I fully understood your requirement. Based on my understanding , you want github workflow to receive deployment evetnt payload and use the payload content in your workflow run. There is a github context for you to use which includes the deployment event payload. And you could use ${{ }} syntax to get the value of json key value. Such as ${{ github.event.deployment.environment }} There is an example of workflow yml to get environment name:
|
Beta Was this translation helpful? Give feedback.
-
right, i wasn’t aware of this, the github context works for me, the payload can be any format, so i use jq in shell to extract the value:
thanks. |
Beta Was this translation helpful? Give feedback.
-
There are ways to do this using workflow_dispatch, if that works for your use case. I tried with repository_dispatch also myself, but it doesn't seem like it accepts inputs, or if so, it's not (well) documented. Check the link above to see how to format your headers = {
"Authorization": f"Bearer {CONFIG['personal_access_token']}",
"Accept": "application/vnd.github.v3+json",
"Content-Type": "application/json"
}
ref = 'develop'
workflow_id = 'resolve_fetch_failures_0_members.yml'
url = f'https://api.github.com/repos/jhu-bids/TermHub/actions/workflows/{workflow_id}/dispatches'
payload = {'ref': ref}
if params:
payload['inputs'] = params
response = requests.post(url, headers = headers,data=json.dumps(payload)) |
Beta Was this translation helpful? Give feedback.
Hi @missedone ,
I am not sure whether I fully understood your requirement. Based on my understanding , you want github workflow to receive deployment evetnt payload and use the payload content in your workflow run.
There is a github context for you to use which includes the deployment event payload.
And you could use ${{ }} syntax to get the value of json key value. Such as
${{ github.event.deployment.environment }}
There is an example of workflow yml to get environment name: