Nicholas Pini
03/24/2026, 1:02 PMMarvin
03/24/2026, 1:02 PMMarvin
03/24/2026, 1:02 PMNicholas Pini
03/24/2026, 1:02 PMMarvin
03/24/2026, 1:02 PMMarvin
03/24/2026, 1:05 PM{
"my_var": "{{ flow_run.job_variables.my_var }}"
}
or safely:
{
"my_var": "{{ flow_run.job_variables.get('my_var') }}"
}
- Important: this gives you only the job variables that were attached to the flow run itself. It does not automatically include defaults from the deployment or work pool, nor the final “resolved” variables the worker computed at run time.
If the value might come from other layers, you can use fallbacks in the template:
{
"image": "{{ flow_run.job_variables.get('image')
or deployment.job_variables.get('image')
or work_pool.base_job_template.variables.get('image') }}"
}
If you truly need the fully resolved job variables used by the worker, they aren’t exposed to automations. Common workarounds:
- Emit a custom event from within your flow (after the worker has resolved variables) that includes the values you need, then trigger the webhook off that event.
- Have your webhook receiver query Prefect for the flow run plus deployment/work pool and reconstruct the value with the same precedence (run → deployment → work pool).
- Push the needed value into the flow run’s job variables when creating the run so it’s directly available as flow_run.job_variables.<key>.
If you share the exact key you want (and your worker type), I can help you craft the precise template snippet.Nicholas Pini
03/24/2026, 1:09 PMMarvin
03/24/2026, 1:09 PMMarvin
03/24/2026, 1:14 PMfrom prefect.blocks.webhook import Webhook
webhook = Webhook(
url="<https://webhook.site/your-unique-url>",
method="POST",
headers={"Content-Type": "application/json"}
)
webhook.save("notify-completions", overwrite=True)
- Get the block’s UUID (block_document_id):
prefect block inspect webhook/notify-completions
Copy the “ID” value from the output.
Step 1 — Define the automation (YAML)
Replace BLOCK_DOCUMENT_ID_HERE with the UUID from Step 0.
Save as webhook-auto.yaml:
name: "Flow Run Completion Webhook"
description: "Send a webhook on flow-run completion including a job variable from the run"
enabled: true
trigger:
type: event
posture: Reactive
expect:
- prefect.flow-run.Completed
threshold: 1
within: 0
actions:
- type: call-webhook
block_document_id: "BLOCK_DOCUMENT_ID_HERE"
payload: |
{
"automation": "{{ automation.name }}",
"event_id": "{{ event.id }}",
"flow_run_id": "{{ flow_run.id }}",
"flow_run_name": "{{ flow_run.name }}",
"state": "{{ flow_run.state.name }}",
"my_var_from_job_variables": "{{ flow_run.job_variables.get('my_var') }}",
"all_job_variables": {{ flow_run.job_variables | tojson if flow_run.job_variables else 'null' }},
"ui_url": "{{ flow_run | ui_url }}"
}
Notes:
- {{ flow_run.job_variables.get('my_var') }} is the job variable reference.
- tojson safely serializes the entire job_variables dict if you want to include everything.
Step 2 — Create the automation
prefect automations create --from-file webhook-auto.yaml
Step 3 — Trigger a flow run with a job variable
You can attach a job variable when creating a run. For strings, pass valid JSON (so quote the value). Example:
prefect deployment run <FLOW_NAME>/<DEPLOYMENT_NAME> \
-jv my_var='"hello from CI"' \
--watch
When the run completes, your automation will fire and the webhook body will include:
- `my_var_from_job_variables`: hello from CI
- `all_job_variables`: {"my_var": "hello from CI"} (plus anything else present)
Tips:
- If you prefer a different key, just change my_var in both the -jv flag and the template.
- The job variables available here are those set on the flow run itself (not the final “resolved” variables after worker merging). If you need resolved values, let me know your worker type and I can suggest a pattern to emit them from within the flow.