Pada 15 September 2026, semua lingkungan Cloud Composer 1 dan Cloud Composer 2 versi 2.0.x akan mencapai akhir masa pakainya yang direncanakan, dan Anda tidak akan dapat menggunakannya. Sebaiknya rencanakan migrasi ke Cloud Composer 3.
Halaman ini menjelaskan cara menyetel variabel lingkungan di lingkungan Cloud Composer Anda.
Anda dapat menggunakan variabel lingkungan sebagai alternatif untuk
variabel Airflow saat memberikan konfigurasi runtime
untuk DAG Anda. Variabel Airflow ditetapkan di database Airflow, sedangkan
variabel lingkungan ditetapkan di container pekerja Airflow.
Sebagai contoh, Anda dapat menggunakan nama variabel lingkungan apa adanya dalam perintah
yang dijalankan oleh BashOperator, atau mendapatkan nilai ini dari objek os.environ
di DAG, atau menggunakan variabel Airflow.
Variabel lingkungan bersifat persisten. Setelah Anda menentukan variabel lingkungan,
Airflow akan terus menggunakannya hingga Anda menghapus variabel dari lingkungan Anda.
Cloud Composer menetapkan variabel lingkungan yang dicadangkan sendiri untuk mengontrol
lingkungan.
Format nama
Variabel lingkungan harus cocok dengan ekspresi reguler
[a-zA-Z_][a-zA-Z0-9_]*.
Opsi konfigurasi Airflow
Anda tidak dapat menentukan variabel yang mengubah opsi konfigurasi Apache Airflow.
Variabel tidak dapat menggunakan format AIRFLOW__{SECTION}__{KEY} atau cocok dengan
ekspresi reguler AIRFLOW__[A-Z0-9_]+__[A-Z0-9_]+. Misalnya, AIRFLOW__WEBSERVER__DAG_DEFAULT_VIEW tidak dapat disetel.
Dalam parameter updateMask, tentukan mask
config.softwareConfig.envVariables untuk mengganti semua variabel yang ada
dengan variabel yang ditentukan. Variabel yang tidak Anda tentukan akan dihapus.
Dalam isi permintaan, tentukan variabel dan nilainya:
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-09-03 UTC."],[[["\u003cp\u003eEnvironment variables in Cloud Composer provide runtime configuration for DAGs, acting as an alternative to Airflow variables by residing in the Airflow worker's container.\u003c/p\u003e\n"],["\u003cp\u003eYou can set and manage environment variables for both new and existing Cloud Composer environments via the Google Cloud console, \u003ccode\u003egcloud\u003c/code\u003e command-line tool, API requests, and Terraform.\u003c/p\u003e\n"],["\u003cp\u003eEnvironment variables must adhere to a specific name format (\u003ccode\u003e[a-zA-Z_][a-zA-Z0-9_]*\u003c/code\u003e) and cannot be used to modify Airflow configuration options; those should be overridden separately.\u003c/p\u003e\n"],["\u003cp\u003eCloud Composer has reserved environment variable names that users cannot create, and these reserved names should not be referenced in DAGs, as their values are subject to change.\u003c/p\u003e\n"],["\u003cp\u003eManaging existing environment variables allows for adding, changing or deleting variables; additionally, deleting all existing variables at once is possible via command-line.\u003c/p\u003e\n"]]],[],null,["# Set environment variables\n\n\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** \\| [Cloud Composer 1](/composer/docs/composer-1/set-environment-variables \"View this page for 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-2/override-airflow-configurations) instead.\n\nCloud Composer sets its own reserved environment variables for controlling\nenvironments.\n\nName format\n-----------\n\nEnvironment variables must match the regular expression\n`[a-zA-Z_][a-zA-Z0-9_]*`.\n\nAirflow configuration options\n-----------------------------\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-2/override-airflow-configurations).\n\nReserved variables\n------------------\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----------------------------------------------\n\nYou can specify environment variables when you create an environment. For more\ninformation, see [Create environments](/composer/docs/composer-2/create-environments#overrides-env-vars).\n\nSet environment variables for existing environments\n---------------------------------------------------\n\n### Console\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\n### gcloud\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\n### API\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\n### Terraform\n\nThe `env_variables` block in the `software_config` block specifies\nenvironment variables. \n\n resource \"google_composer_environment\" \"example\" {\n provider = google-beta\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 provider = google-beta\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\n- [Override Airflow configuration options](/composer/docs/composer-2/override-airflow-configurations)\n- [Update environments](/composer/docs/composer-2/update-environments)"]]