Passing context when triggering a deployment from an automation

I’m interested in using automation so that:

  1. Automation gets triggered whenever a flow matching a certain tag is completed, e.g. I might have flows A, B, C each with tag automate;
  2. A deployment X is then triggered.

Is there a way to get some context passed into the deployment X in step (2), so that it knows which flow, A, B or C caused it to be triggered?

Hi @tjc, thanks for this question. This isn’t super well documented, but similar to how one can use template values in notifications, you can actually pass jinja variables to deployments at action runtime. I’m thinking you could add a string parameter to a deployment and then use a run deployment action with {{ event }} as the parameter, which will resolve at runtime to give you the triggering event which you can use in code. Are you in the slack community? If so hit me up at Will Raphaelson and we can pair on this if its unclear.

1 Like

Thanks @Will_Raphaelson - I got this working as you suggested. In case anyone else is looking to do something similar, the changes I made were as follows:

The flow now accepts an extra string parameter, i.e.

from prefect import flow, get_run_logger

@flow(name="automation-test")
def automation_test(context: str) -> None:
    logger = get_run_logger()

    logger.info("Hello, world!")
    logger.info(f"Context: {context}")

Then when setting up the ‘Action’ part of the automation, I populated the new context variable as follows: