0

我有以下配置:

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

如果我运行:

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

我收到以下消息:

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

如果我声明替换:

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

它运行,但替换只采用第一个变量,其他成为它的值:

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
4

1 回答 1

2

您的命令中有一个语法 nit 应该通过以下方式解决:

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

提交构建后:

B: 分支 T: 标签 C => 客户

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

于 2022-02-02T13:56:48.807 回答