Search code examples
google-cloud-platformgcloudgoogle-cloud-buildcloudbuild.yaml

gcloud builds submit substitutions not working properly. (ERROR: (gcloud.builds.submit) INVALID_ARGUMENT.)


I have the following config:

steps:
- name: 'alpine'
  args: ['echo', 'B: ${_BRANCH}', 'T: ${_TAG}', 'C => ${_CLIENT}']

If I run with:

gcloud builds submit --config=gcp/cloudbuild-main.yaml --substitutions _CLIENT='client',_BRANCH='branch',_TAG='tag' .

I get the following message:

ERROR: (gcloud.builds.submit) INVALID_ARGUMENT: generic::invalid_argument: key in the template "_BRANCH" is not matched in the substitution data; substitutions = map[_CLIENT:client _BRANCH=branch _TAG=tag];key in the template "_TAG" is not matched in the substitution data; substitutions = map[_CLIENT:client _BRANCH=branch _TAG=tag];key "_CLIENT" in the substitution data is not matched in the template

If I declare the substitutions:

steps:
- name: 'alpine'
  args: ['echo', 'B: ${_BRANCH}', 'T: ${_TAG}', 'C => ${_CLIENT}']
substitutions:
  _BRANCH: b1
  _TAG: latest
  _CLIENT: c

It runs but the substitutions take only the first variable and other become values of it:

BUILD
Pulling image: alpine
Using default tag: latest
latest: Pulling from library/alpine
Digest: sha256:21a3deaa0d32a8057914f36584b5288d2e5ecc984380bc0118285c70fa8c9300
Status: Downloaded newer image for alpine:latest
docker.io/library/alpine:latest
B: b1 T: latest C => client _BRANCH=branch _TAG=tag
PUSH
DONE

Solution

  • There's a syntax nit in your command which should be resolved by:

    gcloud builds submit --config=gcp/cloudbuild-main.yaml --substitutions=_CLIENT="client",_BRANCH="branch",_TAG="tag" .
    

    After submitting the build:

    B: branch T: tag C => client

    Reference: https://cloud.google.com/build/docs/configuring-builds/substitute-variable-values