Am 15. September 2026erreichen alle Cloud Composer 1- und Cloud Composer 2-Umgebungen der Version 2.0.x das geplante Ende des Lebenszyklus und können nicht mehr verwendet werden. Wir empfehlen, die Migration zu Cloud Composer 3 zu planen.
Auf dieser Seite wird erläutert, wie Sie Umgebungsvariablen in Ihrer Cloud Composer-Umgebung festlegen.
Sie können Umgebungsvariablen als Alternative zu Airflow-Variablen verwenden, wenn Sie eine Laufzeitkonfiguration für Ihre DAGs angeben. Airflow-Variablen werden in der Airflow-Datenbank festgelegt, während Umgebungsvariablen im Container des Airflow-Workers festgelegt werden.
Sie können beispielsweise den Namen einer Umgebungsvariablen in einem Befehl verwenden, der von einem BashOperator ausgeführt wird, oder diesen Wert aus dem os.environ-Objekt im DAG abrufen oder stattdessen eine Airflow-Variable verwenden.
Umgebungsvariablen sind persistent. Nachdem Sie eine Umgebungsvariable angegeben haben, verwendet Airflow diese so lange, bis Sie die Variable aus Ihrer Umgebung entfernen.
Cloud Composer legt eigene reservierte Umgebungsvariablen für die Steuerung von Umgebungen fest.
Namensformat
Umgebungsvariablen müssen dem regulären Ausdruck [a-zA-Z_][a-zA-Z0-9_]* entsprechen.
Airflow-Konfigurationsoptionen
Es ist nicht möglich, Variablen anzugeben, die die Konfigurationsoptionen von Apache Airflow ändern.
Die Variablen können also nicht das Format AIRFLOW__{SECTION}__{KEY} oder den regulären Ausdruck AIRFLOW__[A-Z0-9_]+__[A-Z0-9_]+ verwenden. Es ist beispielsweise nicht möglich, AIRFLOW__WEBSERVER__DAG_DEFAULT_VIEW festzulegen.
Geben Sie im Parameter updateMask die Maske config.softwareConfig.envVariables an, um alle vorhandenen Variablen durch die angegebenen Variablen zu ersetzen. Nicht angegebene Variablen werden gelöscht.
Geben Sie im Anfragetext Variablen und ihre Werte an:
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-08-29 (UTC)."],[[["\u003cp\u003eEnvironment variables in Cloud Composer provide runtime configuration for DAGs, distinct from Airflow variables stored in the Airflow database.\u003c/p\u003e\n"],["\u003cp\u003eThese environment variables are persistent, remaining in effect until they are explicitly removed from the environment.\u003c/p\u003e\n"],["\u003cp\u003eCertain environment variable names are reserved by Cloud Composer and cannot be used for custom variables, and variables that configure Airflow itself are not allowed.\u003c/p\u003e\n"],["\u003cp\u003eEnvironment variables can be set for both new and existing environments using the Google Cloud console, gcloud command-line tool, API requests, or Terraform.\u003c/p\u003e\n"],["\u003cp\u003eWhen updating variables for existing environments via API, it is done through the \u003ccode\u003eenvironments.patch\u003c/code\u003e method, replacing all existing variables with the new variables specified in the request body.\u003c/p\u003e\n"]]],[],null,["\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\n[Cloud Composer 3](/composer/docs/composer-3/set-environment-variables \"View this page for Cloud Composer 3\") \\| [Cloud Composer 2](/composer/docs/composer-2/set-environment-variables \"View this page for Cloud Composer 2\") \\| **Cloud Composer 1**\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nThis page explains how to set environment variables in your\nCloud Composer environment.\n\nYou can use environment variables as an alternative to\n[Airflow variables](https://airflow.apache.org/docs/apache-airflow/stable/core-concepts/variables.html) when providing runtime configuration\nfor your DAGs. Airflow variables are set in the Airflow database, while\nenvironment variables are set in the Airflow worker's container.\n\nAs an example, you can use an environment variable's name as is in a command\nthat is run by a BashOperator, or get this value from the `os.environ` object\nin the DAG, or use an Airflow variable instead.\n\nEnvironment variables are persistent. Once you specify an environment variable,\nAirflow keeps using it until you remove the variable from your environment.\n| **Important:** It's not possible to use environment variables to configure Airflow. [Override Airflow configuration options](/composer/docs/composer-1/override-airflow-configurations) instead.\n\nCloud Composer sets its own reserved environment variables for controlling\nenvironments.\n\nName format\n\nEnvironment variables must match the regular expression\n`[a-zA-Z_][a-zA-Z0-9_]*`.\n\nAirflow configuration options\n\nIt is not possible to specify variables that change Apache Airflow\nconfiguration options.\n\nThe variables cannot use the `AIRFLOW__{SECTION}__{KEY}` format or match the\nregular expression `AIRFLOW__[A-Z0-9_]+__[A-Z0-9_]+`. For example, it is not\npossible to set `AIRFLOW__WEBSERVER__DAG_DEFAULT_VIEW`.\n\nInstead, you can [override Airflow configuration options](/composer/docs/composer-1/override-airflow-configurations).\n\nReserved variables\n\nThe following variable names are reserved by Cloud Composer. It is\nnot possible to create variables with these names.\n\n- `AIRFLOW_DATABASE_VERSION`\n- `AIRFLOW_HOME`\n- `AIRFLOW_SRC_DIR`\n- `AIRFLOW_WEBSERVER`\n- `AUTO_GKE`\n- `CLOUDSDK_METRICS_ENVIRONMENT`\n- `CLOUD_LOGGING_ONLY`\n- `COMPOSER_AGENT_BUILD_SERVICE_ACCOUNT`\n- `COMPOSER_ENVIRONMENT`\n- `COMPOSER_GKE_LOCATION`\n- `COMPOSER_GKE_NAME`\n- `COMPOSER_GKE_ZONE`\n- `COMPOSER_LOCATION`\n- `COMPOSER_OPERATION_UUID`\n- `COMPOSER_PYTHON_VERSION`\n- `COMPOSER_VERSION`\n- `CONTAINER_NAME`\n- `C_FORCE_ROOT`\n- `DAGS_FOLDER`\n- `GCE_METADATA_TIMEOUT`\n- `GCP_PROJECT`\n- `GCP_TENANT_PROJECT`\n- `GCSFUSE_EXTRACTED`\n- `GCS_BUCKET`\n- `GKE_CLUSTER_NAME`\n- `GKE_IN_TENANT`\n- `GOOGLE_APPLICATION_CREDENTIALS`\n\n- `MAJOR_VERSION`\n\n- `MINOR_VERSION`\n\n- `PATH`\n\n- `PIP_DISABLE_PIP_VERSION_CHECK`\n\n- `PORT`\n\n- `PROJECT_ID`\n\n- `PYTHONPYCACHEPREFIX`\n\n- `PYTHONWARNINGS`\n\n- `REDIS_PASSWORD`\n\n- `REDIS_PORT`\n\n- `REDIS_USER`\n\n- `SQL_DATABASE`\n\n- `SQL_HOST`\n\n- `SQL_INSTANCE`\n\n- `SQL_PASSWORD`\n\n- `SQL_PROJECT`\n\n- `SQL_REGION`\n\n- `SQL_USER`\n\n| **Caution:** Cloud Composer uses these reserved names for variables that are used by its processes. Don't refer to reserved names in your DAGs. Values of these variables can change without notice.\n\nSet environment variables for new environments\n\nYou can specify environment variables when you create an environment. For more\ninformation, see [Create environments](/composer/docs/composer-1/create-environments#overrides-env-vars).\n\nSet environment variables for existing environments \n\nConsole\n\nTo set environment variables for an existing environment:\n\n1. In Google Cloud console, go to the **Environments** page.\n\n [Go to Environments](https://console.cloud.google.com/composer/environments)\n2. In the list of environments, click the name of your environment.\n The **Environment details** page opens.\n\n3. Go to the **Environment variables** tab and click **Edit**.\n\n4. Add, change, or delete environment variables for your environment:\n\n - In the **Name** field, specify the variable name.\n - In the **Value** field, specify the variable value.\n - To add an extra variable, click **Add environment variable**.\n - To delete a variable, hold the pointer over a variable, then click **Delete item**.\n\ngcloud\n\nFollowing arguments control environment variables:\n\n- `--update-env-variables` specifies a comma-separated list of environment\n variables to create or update.\n\n- `--remove-env-variables` specifies a comma-separated list of environment\n variables to delete.\n\n- `--clear-env-variables` deletes all existing environment variables.\n\n gcloud composer environments update \\\n \u003cvar translate=\"no\"\u003eENVIRONMENT_NAME\u003c/var\u003e \\\n --location \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e \\\n --update-env-variables=\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-nv\"\u003eNAME\u003c/span\u003e\u003c/var\u003e=\u003cvar translate=\"no\"\u003eVALUE\u003c/var\u003e\n\nReplace:\n\n- `ENVIRONMENT_NAME` with the name of the environment.\n- `LOCATION` with the region where the environment is located.\n- `NAME` with the name of the variable that you want to create or update.\n- `VALUE` with the value for the variable.\n- To add more than one variable, separate the definitions with commas: `NAME=VALUE,NAME=VALUE,...`.\n\nExample: \n\n gcloud composer environments update \\\n example-environment \\\n --location us-central1 \\\n --update-env-variables=EXAMPLE_VARIABLE=True,ANOTHER_VARIABLE=test\n\nAPI\n\nConstruct an [`environments.patch`](/composer/docs/reference/rest/v1/projects.locations.environments/patch) API request.\n\nIn this request:\n\n1. In the `updateMask` parameter, specify the\n `config.softwareConfig.envVariables` mask to replace all existing\n variables with the specified variables. Variables that you don't specify\n are deleted.\n\n2. In the request body, specify variables and their values:\n\n {\n \"config\": {\n \"softwareConfig\": {\n \"envVariables\": {\n \"\u003cvar translate=\"no\"\u003eVAR_NAME\u003c/var\u003e\": \"\u003cvar translate=\"no\"\u003eVAR_VALUE\u003c/var\u003e\"\n }\n }\n }\n }\n\n Replace:\n - `VAR_NAME` with the name of the environment variable.\n - `VAR_VALUE` with the value of the environment variable.\n - To add more than one variable, add extra entries for variables to `envVariables`.\n\nExample: \n\n // PATCH https://composer.googleapis.com/v1/projects/example-project/\n // locations/us-central1/environments/example-environment?updateMask=\n // config.softwareConfig.envVariables\n {\n \"config\": {\n \"softwareConfig\": {\n \"envVariables\": {\n \"EXAMPLE_VARIABLE\": \"True\",\n \"ANOTHER_VARIABLE\": \"test\"\n }\n }\n }\n }\n\nTerraform\n\nThe `env_variables` block in the `software_config` block specifies\nenvironment variables. \n\n resource \"google_composer_environment\" \"example\" {\n name = \"\u003cvar translate=\"no\"\u003eENVIRONMENT_NAME\u003c/var\u003e\"\n region = \"\u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e\"\n\n config {\n\n software_config {\n\n env_variables = {\n \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-na\"\u003eVAR_NAME\u003c/span\u003e\u003c/var\u003e = \"\u003cvar translate=\"no\"\u003eVAR_VALUE\u003c/var\u003e\"\n }\n\n }\n }\n }\n\nReplace:\n\n- `ENVIRONMENT_NAME` with the name of the environment.\n- `LOCATION` with the region where the environment is located.\n- `VAR_NAME` with the name of the environment variable.\n- `VAR_VALUE` with the value of the environment variable.\n- To add more than one variable, add extra entries for variables to `env_variables`.\n\nExample: \n\n resource \"google_composer_environment\" \"example\" {\n name = \"example-environment\"\n region = \"us-central1\"\n\n config {\n\n software_config {\n\n env_variables = {\n EXAMPLE_VARIABLE = \"True\"\n ANOTHER_VARIABLE = \"test\"\n }\n }\n }\n }\n\nWhat's next\n\n- [Override Airflow configuration options](/composer/docs/composer-1/override-airflow-configurations)\n- [Update environments](/composer/docs/composer-1/update-environments)"]]