Professional Cloud Developer free question 5 / 10 · Domain 2: Building and testing applications
A build config references $ENV_NAME in an image tag, and the team passes the value as ENV_NAME=staging on the command line. The build is rejected because $ENV_NAME is not a built-in substitution. How should the team name the variable?
- Rename it _ENV_NAME, so that it begins with an underscore and uses just uppercase letters, numbers and underscores
- Rename it _env_name, as a leading underscore marks a variable as user-defined
- Keep ENV_NAME and declare it under the substitutions field of the config, as declared names do not need a prefix
- Rename it $$ENV_NAME, as a double dollar sign declares a user-defined substitution
Show the answer and explanation
Answer: A
Why this is correct
Cloud Build reserves names without a leading underscore for its built-in substitutions, such as $PROJECT_ID and $BUILD_ID. User-defined substitutions therefore must begin with an underscore and use only uppercase letters and numbers, matching the regular expression _[A-Z0-9_]+. The page gives $FOO as an invalid example because it is not a built-in substitution, which is why the original build was rejected. The page also states limits for user-defined substitutions: up to 200 parameters, with a parameter key of up to 100 bytes and a parameter value of up to 4000 bytes.
Why the other options are wrong
"Rename it _env_name, as a leading underscore marks a variable as user-defined" … A user-defined substitution must also follow the regular expression _[A-Z0-9_]+, which means uppercase letters and numbers after the underscore.
"Rename it $$ENV_NAME, as a double dollar sign declares a user-defined substitution" … The page uses $$ to write a literal dollar sign. $$FOO evaluates to the literal string $FOO, so this is not a substitution at all.
"Keep ENV_NAME and declare it under the substitutions field of the config, as declared names do not need a prefix" … Declaring the value in the config does not change the naming rule. Without the leading underscore, $ENV_NAME can be confused with built-in substitutions.
Key point
Name your own substitutions with a leading underscore and uppercase letters, such as _ENV_NAME. This keeps them clear of the built-in ones.