Sometimes, we need a way to configure the variables from the admin UI of airflow so that we can change the value of that variable whenever required. Instead of digging into code and modify it and then deploy and test.

Airflow provides an easy way to set the variable from admin UI. Follow the below steps to get it done.

Step 1: Login into airflow admin UI and go to Admin > Variables from the top navigation menu. You will see the list of variables here. If you are doing first time then this list is empty else you will see the variables set by you earlier.

Step 2: Hit the plus(+) icon to add a new variable.

Step 3: Set the key and value of the variable. Key is the name of the variable and value is self-explanatory. In our case, we want to store the email address and we will use this email address to send the DAG failure email. It will look like below screenshot.

Step 4: Use of above defined variable into DAG. First import package to use variable and then get the value of variable and use it into code.

from airflow.models import Variable

# Fetch the set value of dag_email_recipient variable.
dag_email_recipient = Variable.get("dag_email_recipient")

Now you can use the dag_email_recipient variable in your code.