【发布时间】:2020-02-19 14:49:02
【问题描述】:
从这里...https://cloud.google.com/cloud-build/docs/configuring-builds/substitute-variable-values
我正在尝试在 cloudbuild.yaml 文件中使用替换,但几乎所有替换都取决于我正在部署到的项目的项目 ID。
我有这样的 yaml 文件...
steps:
- name: 'gcr.io/cloud-builders/gcloud'
args: ['functions', 'deploy', 'functionName', ...other args... , '--service-account', '${_SERVICE_ACCOUNT}', '--source', '${_SOURCE_REPO}']
substitutions:
_SOURCE_REPO: 'https://source.developers.google.com/projects/$PROJECT_ID/repos/my-repo-id/moveable-aliases/master/paths/functions/src'
_SERVICE_ACCOUNT: 'blah@${PROJECT_ID}.iam.gserviceaccount.com'
无论我尝试什么替换(我尝试了两种格式$_FOO 和${_FOO}),我最终得到的是blah@${PROJECT_ID}.iam.gserviceaccount.com,其中${PROJECT_ID} 文本仍然存在,而不是实际项目身份证。
如果我将文本移动到步骤中并仅使用它而不是替换,那么它就可以工作。但理想情况下,我想使用这种方法,因为这些值会被大量使用,所以想节省重复。
编辑
嗯,我尝试了几个不同的选项,包括@ralemos 提到的一些建议,但似乎没有任何效果。
如果我使用这种格式...
steps:
- name: 'gcr.io/cloud-builders/gcloud'
args: ['functions', 'deploy', 'functionName', ...other args... , '--service-account', '${SERVICE_ACCOUNT}', '--source', '${SOURCE_REPO}']
options:
env:
SOURCE_REPO: 'https://source.developers.google.com/projects/${PROJECT_ID}/repos/my-repo-id/moveable-aliases/master/paths/functions/src'
SERVICE_ACCOUNT: 'blah@${PROJECT_ID}.iam.gserviceaccount.com
它抱怨 env 行无效。
如果我使用这种格式...
steps:
- name: 'gcr.io/cloud-builders/gcloud'
args: ['functions', 'deploy', 'functionName', ...other args... , '--service-account', '${SERVICE_ACCOUNT}', '--source', '${SOURCE_REPO}']
options:
env:
'SOURCE_REPO=https://source.developers.google.com/projects/${PROJECT_ID}/repos/my-repo-id/moveable-aliases/master/paths/functions/src'
'SERVICE_ACCOUNT=blah@${PROJECT_ID}.iam.gserviceaccount.com
它抱怨SERVICE_ACCOUNT 和SOURCE_REPO 不是有效的内置替换。
如果我使用 $$SOURCE_REPO 作为语法,它只是将其替换为 $SOURCE_REPO 而不是使用替换。
目前看来,我正在尝试的事情是不可能的。
【问题讨论】: