0

I run airflow on Kubernetes (so don't want a solution involving CLI commands, everything should be doable via the GUI ideally.)

I have some task and want to inject a variable to the command manually only. I can achieve this with airflow variables, but the user has to create then reset the variable.

With variables it might look like:

flag = Variable.get(
    "NAME_OF_VARIABLE", False
)
append_args = "--injected-argument" if flag == "True" else ""

Or you could use jinja templating.

Is there a way to inject variables one off to the task without the CLI?

jabberwocky
  • 995
  • 10
  • 18
  • I suppose i could add a task to reset the variable - but that feels quite hacky – jabberwocky Aug 31 '21 at 11:18
  • You can find examples about how to pass parameters while triggering the DAG from the UI in [this answer](https://stackoverflow.com/a/68107775/10569220). – NicoE Aug 31 '21 at 11:47

1 Answers1

0

There's no way to pass a value to one single task in Airflow, but you can trigger a DAG and provide a JSON object for that one single DAG run.

The JSON object is accessible when templating as {{ dag_run.conf }}.

Bas Harenslak
  • 2,591
  • 14
  • 14
  • Ah interesting, so as long as I'm happy to pass the param to all the tasks in the dag, then I can do it. It seems like the variable plus reset is possibly my best path for manual implementation over specific tasks runs and reruns then. – jabberwocky Aug 31 '21 at 11:21