Search code examples
gcloudsubstitution

GCloud build YAML substitutions don't work


I have a build config file that looks like:

steps:
...
<i use the ${_IMAGE} variable around 4 times here>
...
images: ['${_IMAGE}']
options:
   dynamic_substitutions: true
substitutions:
   _IMAGE: http://example.com/image-${_ENVIRON}

And I trigger the build like:

gcloud builds submit . --config=config.yaml --substitutions=_ENVIRON=prod

What I expected is for the gcloud to substitute the _ENVIRON variable in my script and then substitute the _IMAGE variable so that it'd expand to 'http://example.com/image-prod' - but instead I'm getting the following error:

ERROR: (gcloud.builds.submit) INVALID_ARGUMENT: generic::invalid_argument: key "_ENVIRON" in the substitution data is not matched in the template

What can I do to make that work? I really want to be able to change the environment easily with a sub and without the need to change anything in code


Solution

  • As you've seen, this isn't possible.

    If the only use of _ENVIRON is by _IMAGE, why not drop the substitions from config.yaml and use _IMAGE as the substitution:

    ENVIRON="prod"
    IMAGE: http://example.com/image-${ENVIRON}
    
    gcloud builds submit . \
    --config=config.yaml \
    --substitutions=_IMAGE=${IMAGE}