<@ULVA73B9P> can prefect listen to a specific even...
# marvin-ai
f
@Marvin can prefect listen to a specific even, for instance a new tag pushed to gitlab
m
thought for 252.7 seconds
Yes. In Prefect 3.x you can react to external events like “tag pushed to GitLab” and trigger a flow. The most common paths are: - Prefect Cloud Webhooks → Automations → Run a deployment (recommended for GitLab) - Emit events directly to the Prefect Events API (OSS or Cloud) - Deployment event triggers in code (listen for events and start runs) Quick start for GitLab tag pushes (Cloud): 1) Create a Prefect Cloud Webhook with a Jinja template that turns GitLab’s payload into a Prefect event. Example template:
Copy code
{
  "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:
Copy code
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:
Copy 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?