GoogleCloudPlatform/cloud-build-local

--substitutions is broken in gcloud v201

Closed this issue · 13 comments

(I'm sorry if it's not the correct way to report bug for this tool.)

In the latest gcloud v201, the --substitutions flag doesn't work anymore for container-builder-local.
It displays errors like this:

2018/05/17 17:02:30 Error validating build: key in the template "_VERSION" is not matched in the substitution data;key in the template "_VERSION" is not matched in the substitution data;key in the template "_VERSION" is not matched in the substitution data

I don't have any issue with gcloud v200.

PS: it seems that the component was updated from 0.2.7 to 0.3.1

Actually it's maybe not a bug.
It seems that where the key is already defined in the build request was added in the help message.

I was using the previous behavior in order to ensure that the substitutions are always provided in the command line.

Could you share a snippet of the config? And the command you use to start the build?

steps:
  - name: 'gcr.io/cloud-builders/docker'
    args:
      - 'image'
      - 'build'
      - '--build-arg'
      - 'VERSION=${_VERSION}'
      - '--tag'
      - 'gcr.io/${PROJECT_ID}/xxx:latest'
      - '--tag'
      - 'gcr.io/${PROJECT_ID}/xxx:${_VERSION}'
      - '.'
images:
  - 'gcr.io/${PROJECT_ID}/xxx:latest'
  - 'gcr.io/${PROJECT_ID}/xxx:${_VERSION}'

With gcloud container builds submit, if I forget the --substitutions="_VERSION=test" flag, there is an error message.
It was the same behavior for the version 0.2.7 of container-builder-local.

In container-builder-local 0.3.1, it seems mandatory to declare a substitution in the config file before using it.

Thanks for reporting this bug, I'm working on a fix.

Pierre, I'm having the same issue.
How do you declare a substitution in the config file?
I did it like this:

options: machineType: 'N1_HIGHCPU_8' substitutions: _VERSION: 7.2.4

I expect 7.2.4 to be the default value, that can be overridden on the command line. However, upon executing a dry run, the output shows the variable as empty. The only way to make it work is to give it an explicit value on the command line:

container-builder-local -config cloudbuild/cloudbuild.yaml --substitutions="BRANCH_NAME=test,_VERSION=1.0.0" .

Is this the normal behavior?

Yes, I do exactly like that.

However I never used "dry run", so I don't know what was the previous behavior.

I can confirm it happens with a regular run as well. If I don't explicitly declare a value for the variable on the command line, it ignores the default value in the YAML.

This is fixed in https://github.com/GoogleCloudPlatform/container-builder-local/releases/tag/v0.3.2

The new version will be released with the cloud sdk, next Wednesday.

thank you ! 👍

Merci!

Hi guys, I'm having the same issue.

My config is:

steps:

  • name: 'alpine'
    args: ['echo', 'B: ${_BRANCH}', 'T: ${_TAG}']

My cmd line is:

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

The result is:

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