AGaur
AGaur

Reputation: 305

Create airflow environment variables

I am very much new to the airflow and need to create environment variables start_date and end_date in airflow UI under admin tab in variables section using the code

Variable.set("start_date")
Variable.set("end_date")

and then retrieving the values of start_date and end_Date passed from airflow UI using

Variable.get("start_date")
Variable.get("end_date")

enter image description here However not getting success because variables are not creating in airflow UI under admin tab in variables section using the code

Can anyone please help me ,how to create the variables using code and then retrieve the values

Upvotes: 0

Views: 1813

Answers (1)

Hossein Torabi
Hossein Torabi

Reputation: 733

Airflow variables stores on the airflow database and it use the key, value structure to store and query variables. So if you want to set any variables on airflow do this on the UI: enter image description here

Also, it's recommended to use JSON value if you use start_date and end_date for example on a specific dag because of it reduce querying from 2 times to 1 time like this: enter image description here

Then you can use the variable like this:

variable = Variable.get("smaple")
start_date = variable['start_date']
end_date = variable['end_date']

Upvotes: 1

Related Questions