Cloud Deployment Manager will reach end of support on December 31, 2025. If you currently use Deployment Manager, please migrate to Infrastructure Manager or an alternative deployment technology by December 31, 2025 to ensure your services continue without interruption.
You can watch a variable for changes by calling the
variables().watch
method. The method watches the variable for 60 seconds and returns if the variable
value changes. If the value doesn't change within 60 seconds, the method
terminates and returns with variable state=VARIABLE_STATE_UNSPECIFIED. If
the variable is deleted, the method returns with a variable state=DELETED and
the last known variable value.
To set a watcher, use Deployment Manager, the Google Cloud CLI, or the
API.
Deployment Manager
This is not supported in Deployment Manager. Create a
waiter
instead.
[TIMEOUT_SEC] is the time in seconds to wait. The default and maximum
amount is 60 seconds.
The gcloud CLI watches the variable and returns after it reaches the
specified timeout period or the variable changes. If the variable changed,
the response contains one of the applicable
variable states.
API
In the API, make a POST request to the following URI:
[CONFIG_NAME] is the name of the RuntimeConfig resource for this
request.
[VARIABLE_KEY] is the key to watch.
Optionally, you can provide a request payload with the newerThan property:
{
"newerThan": "[TIMESTAMP]"
}
where [TIMESTAMP] is a timestamp in RFC 3339 since the epoch in UTC "Zulu"
format. For example:
2014-10-02T15:01:23.045123456Z
If you provide the newerThan property, the method returns immediately if the
current timestamp for the variable is newer than the specified timestamp.
Use the newerThan property to make sure you didn't miss any changes
between watch() calls.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["\u003cp\u003eThis page guides users on how to watch a variable for changes using the \u003ccode\u003evariables().watch\u003c/code\u003e method, which monitors a variable for 60 seconds and reports any changes or if the variable is deleted.\u003c/p\u003e\n"],["\u003cp\u003eTo use the \u003ccode\u003egcloud\u003c/code\u003e command-line tool for watching a variable, use the command \u003ccode\u003egcloud beta runtime-config configs variables watch [VARIABLE_KEY] --max-wait [TIMEOUT_SEC] --config-name [CONFIG_NAME]\u003c/code\u003e, with a maximum wait time of 60 seconds.\u003c/p\u003e\n"],["\u003cp\u003eThe API method \u003ccode\u003evariables().watch\u003c/code\u003e can be used to watch variables, and it allows for the optional \u003ccode\u003enewerThan\u003c/code\u003e property to check if any changes have been missed since the last watch call, and if the variable value is newer than the specified \u003ccode\u003enewerThan\u003c/code\u003e timestamp it will return immediately.\u003c/p\u003e\n"],["\u003cp\u003eDeployment Manager does not support creating a watcher for a variable, and users are instead advised to create a waiter.\u003c/p\u003e\n"],["\u003cp\u003eThis feature is in beta, which means it is subject to the "Pre-GA Offerings Terms", is available "as is," and may have limited support.\u003c/p\u003e\n"]]],[],null,["# Watching a Variable for Changes\n\n| **Beta**\n|\n|\n| This product or feature is subject to the \"Pre-GA Offerings Terms\" in the General Service Terms section\n| of the [Service Specific Terms](/terms/service-terms#1).\n|\n| Pre-GA products and features are available \"as is\" and might have limited support.\n|\n| For more information, see the\n| [launch stage descriptions](/products#product-launch-stages).\n\nThis page explains how to create a watcher for a variable. To learn more\nabout watchers, see\n[Runtime Configurator Fundamentals](/deployment-manager/runtime-configurator).\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- Read [Runtime Configurator Fundamentals](/deployment-manager/runtime-configurator).\n- Read [Creating and Deleting RuntimeConfig Resources](/deployment-manager/runtime-configurator/create-and-delete-runtimeconfig-resources).\n- Read [Setting and Getting Data](/deployment-manager/runtime-configurator/set-and-get-variables).\n\nWatching a variable for change\n------------------------------\n\nYou can watch a variable for changes by calling the\n[`variables().watch`](/deployment-manager/runtime-configurator/reference/rest/v1beta1/projects.configs.variables/watch)\nmethod. The method watches the variable for 60 seconds and returns if the variable\nvalue changes. If the value doesn't change within 60 seconds, the method\nterminates and returns with variable `state=VARIABLE_STATE_UNSPECIFIED`. If\nthe variable is deleted, the method returns with a variable `state=DELETED` and\nthe last known variable value.\n\nTo set a watcher, use Deployment Manager, the Google Cloud CLI, or the\nAPI. \n\n### Deployment Manager\n\nThis is not supported in Deployment Manager. Create a\n[waiter](/deployment-manager/runtime-configurator/creating-a-waiter)\ninstead.\n\n### gcloud\n\nWith the Google Cloud CLI: \n\n gcloud beta runtime-config configs variables watch [VARIABLE_KEY] --max-wait [TIMEOUT_SEC] --config-name [CONFIG_NAME]\n\nwhere:\n\n- `[VARIABLE_KEY]` is the key to watch.\n- `[TIMEOUT_SEC]` is the time in seconds to wait. The default and maximum amount is 60 seconds.\n\nThe gcloud CLI watches the variable and returns after it reaches the\nspecified timeout period or the variable changes. If the variable changed,\nthe response contains one of the applicable\n[variable states](/deployment-manager/runtime-configurator/reference/rest/v1beta1/projects.configs.variables#VariableState).\n\n### API\n\nIn the API, make a `POST` request to the following URI: \n\n https://runtimeconfig.googleapis.com/v1beta1/projects/[PROJECT_ID]/configs/[CONFIG_NAME]/variables/[VARIABLE_KEY]:watch\n\nwhere:\n\n- `[PROJECT_ID]` is the project ID for this request.\n- `[CONFIG_NAME]` is the name of the RuntimeConfig resource for this request.\n- `[VARIABLE_KEY]` is the key to watch.\n\n Optionally, you can provide a request payload with the `newerThan` property:\n\n {\n \"newerThan\": \"\\[TIMESTAMP\\]\"\n }\n\n where `[TIMESTAMP]` is a timestamp in RFC 3339 since the epoch in UTC \"Zulu\"\n format. For example:\n\n 2014-10-02T15:01:23.045123456Z\n\n If you provide the `newerThan` property, the method returns immediately if the\n current timestamp for the variable is newer than the specified timestamp.\n Use the `newerThan` property to make sure you didn't miss any changes\n between `watch()` calls.\n\n The method returns with one of applicable\n [variable states](/deployment-manager/runtime-configurator/reference/rest/v1beta1/projects.configs.variables#VariableState).\n\n To learn more about the method, read the\n [`variables().watch`](/deployment-manager/runtime-configurator/reference/rest/v1beta1/projects.configs.variables/watch)\n documentation.\n\nWhat's next\n-----------\n\n- Learn about [Runtime Configurator](/deployment-manager/runtime-configurator).\n- [Setting and Getting Data](/deployment-manager/runtime-configurator/set-and-get-variables).\n- [Creating a Waiter](/deployment-manager/runtime-configurator/creating-a-waiter).\n- [Creating and Deleting RuntimeConfig Resources](/deployment-manager/runtime-configurator/create-and-delete-runtimeconfig-resources).\n- Refer to the [v1beta1 reference](/deployment-manager/runtime-configurator/reference/rest).\n- Refer to the [Quotas for Runtime Configurator](/deployment-manager/pricing-and-quotas#runtime_configurator)."]]