Fabio Geraci
11/29/2025, 2:45 PMMarvin
11/29/2025, 2:45 PMMarvin
11/29/2025, 2:49 PM{
"event": "gitlab.tag.push",
"resource": {
"prefect.resource.id": "gitlab.project.{{ body.project.id }}.tag.{{ body.ref.split('/')[-1] }}",
"prefect.resource.name": "{{ body.project.name }}",
"gitlab.tag": "{{ body.ref.split('/')[-1] }}",
"gitlab.project_path": "{{ body.project.path_with_namespace }}"
},
"payload": {{ body | tojson }}
}
You can create a webhook via CLI:
prefect cloud webhook create gitlab-tags -t '<paste the JSON template above>'
(Verified: prefect cloud webhook create --help exists.)
2) In GitLab → your project → Settings → Webhooks:
- URL: the unique Prefect webhook URL you created
- Trigger: enable “Tag push events”
- Save
3) Trigger a flow when the event arrives:
- EITHER use Automations (UI): Create an automation with Trigger: event name = gitlab.tag.push (and optionally match your prefect.resource.id pattern), Action: Run a deployment, and map parameters using Jinja like {{ event.resource['gitlab.tag'] }}.
- OR define a deployment with an event trigger in code:
from prefect import flow, serve
from prefect.events import DeploymentEventTrigger
@flow
def on_tag(tag: str):
print(f"New tag: {tag}")
if __name__ == "__main__":
serve(
on_tag.to_deployment(
name="on-gitlab-tag",
triggers=[DeploymentEventTrigger(expect={"gitlab.tag.push"})],
)
)
Then, in the automation or trigger parameters, pass tag from the event (e.g., {{ event.resource['gitlab.tag'] }}).
Alternative (OSS or custom integration):
- Have GitLab (or a small intermediary) emit events directly to Prefect’s Events API, then use an Automation or a DeploymentEventTrigger to start flows.
- API: POST to /api/events with an array of events including event, resource.prefect.resource.id, and any payload.
Docs and references:
- Webhooks overview: Webhooks
- Create a webhook (Cloud): Create a webhook
- Events concepts: Events
- Event triggers and passing payloads to flows:
- Event triggers
- Passing event payloads to flows
- Events REST API: Create events API
A couple of clarifications to tailor this:
- Are you using Prefect Cloud or OSS/self-hosted?
- Do you want to trigger a specific deployment and pass the tag as a parameter?