[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-19。"],[[["\u003cp\u003eDeployment Manager automatically creates environment variables for each deployment, providing information about the project and deployment.\u003c/p\u003e\n"],["\u003cp\u003eThese environment variables, such as \u003ccode\u003edeployment\u003c/code\u003e, \u003ccode\u003eproject\u003c/code\u003e, and \u003ccode\u003eproject_number\u003c/code\u003e, can be used within Jinja2 or Python templates to dynamically configure resources.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003ecurrent_time\u003c/code\u003e environment variable provides a UTC timestamp of when the deployment expansion started.\u003c/p\u003e\n"],["\u003cp\u003eTemplates utilize environment variables using the \u003ccode\u003e{{ env["variable_name"] }}\u003c/code\u003e syntax for Jinja2 and \u003ccode\u003econtext.env["variable_name"]\u003c/code\u003e for Python.\u003c/p\u003e\n"],["\u003cp\u003eEnvironment variables can be used to define or alter resource names and properties within a template, such as appending the deployment name to a VM instance.\u003c/p\u003e\n"]]],[],null,["# Using deployment-specific environment variables\n\nFor each of your deployments, Deployment Manager creates pre-defined\nenvironment variables that contain information inferred from your deployment.\nUse these environment variables in your Python or Jinja2 templates to get\ninformation about your project or deployment.\n\nBefore you begin\n----------------\n\n- If you want to use the command-line examples in this guide, install the [\\`gcloud\\` command-line tool](/sdk).\n- If you want to use the API examples in this guide, set up [API access](/deployment-manager/docs/reference/latest).\n- Understand how to [create a basic template](/deployment-manager/docs/configuration/templates/create-basic-template).\n- Understand how to [create a configuration](/deployment-manager/docs/configuration/create-basic-configuration)\n\nAvailable environment variables\n-------------------------------\n\nThe following environment variables are automatically set by Deployment Manager.\nThey are replaced everywhere you use them in your templates. For example,\nuse the `project_number` variable to add the project number to the name of a\nservice account.\n\nUsing an environment variable\n-----------------------------\n\nUse the following syntax to add an environment variable to your templates: \n\n```django/jinja\n{{ env[\"deployment\"] }} # Jinja\n\ncontext.env[\"deployment\"] # Python\n```\n\nIn your template, use the variables as in these examples: \n\n### Jinja\n\n```django/jinja\n- type: compute.v1.instance\n name: vm-{{ env[\"deployment\"] }}\n properties:\n machineType: zones/us-central1-a/machineTypes/f1-micro\n serviceAccounts:\n - email: {{ env['project_number'] }}-compute@developer.gserviceaccount.com\n scopes:\n - ...\n```\n\n### Python\n\n```python\ndef GenerateConfig(context):\n resources = []\n resources.append ({\n 'name': 'vm-' + context.env[\"deployment\"],\n 'type': 'compute.v1.instance',\n 'properties': {\n 'serviceAccounts': [{\n 'email': context.env['project_number'] + '-compute@developer.gserviceaccount.com',\n 'scopes': [...]\n }]\n }\n ...}]\n return {'resources': resources}\n```\n\nWhat's next\n-----------\n\n- Add a template permanently to your project as a [composite type](/deployment-manager/docs/configuration/templates/create-composite-types).\n- [Host templates externally](/deployment-manager/docs/configuration/templates/hosting-templates-externally) to share with others.\n- Add [schemas](/deployment-manager/docs/configuration/templates/using-schemas) to ensure users interact with your templates correctly."]]